Skip to content

Commit 539d87e

Browse files
authored
docs: sqlite query/getRow use variable annotation, not <T> generic syntax (#515)
Co-authored-by: cs01 <cs01@users.noreply.github.com>
1 parent babbf91 commit 539d87e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/stdlib/sqlite.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const name = sqlite.get(db, "SELECT name FROM users WHERE id = ?", [1]);
2929
// "Alice"
3030
```
3131

32-
## `sqlite.getRow<T>(db, sql, params?)`
32+
## `sqlite.getRow(db, sql, params?)`
3333

34-
Execute a query and return the first row as a typed object, or `null` if no row matches. Fields are accessed by position via type assertion.
34+
Execute a query and return the first row as a typed object, or `null` if no row matches. The row type comes from the variable's type annotation — fields map to columns by position.
3535

3636
```typescript
3737
interface User {
@@ -40,7 +40,7 @@ interface User {
4040
age: string;
4141
}
4242

43-
const user = sqlite.getRow<User>(db, "SELECT id, name, age FROM users WHERE id = ?", [1]);
43+
const user: User | null = sqlite.getRow(db, "SELECT id, name, age FROM users WHERE id = ?", [1]);
4444
if (user !== null) {
4545
console.log(user.name); // "Alice"
4646
}
@@ -55,9 +55,9 @@ const names = sqlite.all(db, "SELECT name FROM users WHERE age > ?", [25]);
5555
// ["Alice", "Charlie"]
5656
```
5757

58-
## `sqlite.query<T>(db, sql, params?)`
58+
## `sqlite.query(db, sql, params?)`
5959

60-
Execute a query and return all rows as a typed object array. This is the recommended API for multi-column queries.
60+
Execute a query and return all rows as a typed object array. The row type comes from the variable's type annotation — fields map to columns by position. This is the recommended API for multi-column queries.
6161

6262
```typescript
6363
interface User {
@@ -66,13 +66,13 @@ interface User {
6666
age: string;
6767
}
6868

69-
const users = sqlite.query<User>(db, "SELECT id, name, age FROM users ORDER BY id");
69+
const users: User[] = sqlite.query(db, "SELECT id, name, age FROM users ORDER BY id");
7070
for (const user of users) {
7171
console.log(user.name + " age " + user.age);
7272
}
7373

7474
// With parameters:
75-
const adults = sqlite.query<User>(
75+
const adults: User[] = sqlite.query(
7676
db,
7777
"SELECT id, name, age FROM users WHERE age >= ?",
7878
["18"]
@@ -101,11 +101,11 @@ interface User {
101101
age: string;
102102
}
103103

104-
const users = sqlite.query<User>(db, "SELECT id, name, age FROM users ORDER BY name");
104+
const users: User[] = sqlite.query(db, "SELECT id, name, age FROM users ORDER BY name");
105105
console.log(users.length); // 2
106106
console.log(users[0].name); // "Alice"
107107

108-
const alice = sqlite.getRow<User>(db, "SELECT id, name, age FROM users WHERE name = ?", ["Alice"]);
108+
const alice: User | null = sqlite.getRow(db, "SELECT id, name, age FROM users WHERE name = ?", ["Alice"]);
109109
if (alice !== null) {
110110
console.log(alice.age); // "30"
111111
}

0 commit comments

Comments
 (0)