You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/stdlib/sqlite.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,9 @@ const name = sqlite.get(db, "SELECT name FROM users WHERE id = ?", [1]);
29
29
// "Alice"
30
30
```
31
31
32
-
## `sqlite.getRow<T>(db, sql, params?)`
32
+
## `sqlite.getRow(db, sql, params?)`
33
33
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.
35
35
36
36
```typescript
37
37
interfaceUser {
@@ -40,7 +40,7 @@ interface User {
40
40
age:string;
41
41
}
42
42
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]);
44
44
if (user!==null) {
45
45
console.log(user.name); // "Alice"
46
46
}
@@ -55,9 +55,9 @@ const names = sqlite.all(db, "SELECT name FROM users WHERE age > ?", [25]);
55
55
// ["Alice", "Charlie"]
56
56
```
57
57
58
-
## `sqlite.query<T>(db, sql, params?)`
58
+
## `sqlite.query(db, sql, params?)`
59
59
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.
61
61
62
62
```typescript
63
63
interfaceUser {
@@ -66,13 +66,13 @@ interface User {
66
66
age:string;
67
67
}
68
68
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");
70
70
for (const user ofusers) {
71
71
console.log(user.name+" age "+user.age);
72
72
}
73
73
74
74
// With parameters:
75
-
const adults=sqlite.query<User>(
75
+
const adults:User[] =sqlite.query(
76
76
db,
77
77
"SELECT id, name, age FROM users WHERE age >= ?",
78
78
["18"]
@@ -101,11 +101,11 @@ interface User {
101
101
age:string;
102
102
}
103
103
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");
105
105
console.log(users.length); // 2
106
106
console.log(users[0].name); // "Alice"
107
107
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"]);
0 commit comments