bun-types 1.2.6 → 1.2.8-canary.20250327T140605
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/bun.d.ts +7187 -7604
- package/bun.ns.d.ts +7 -0
- package/deprecated.d.ts +53 -58
- package/devserver.d.ts +177 -183
- package/docs/api/cookie.md +449 -0
- package/docs/api/fetch.md +1 -1
- package/docs/api/http.md +78 -0
- package/docs/api/spawn.md +1 -1
- package/docs/cli/publish.md +1 -1
- package/docs/guides/ecosystem/nuxt.md +1 -1
- package/docs/guides/install/add-peer.md +2 -2
- package/docs/guides/install/from-npm-install-to-bun-install.md +1 -1
- package/docs/guides/runtime/typescript.md +7 -6
- package/docs/guides/test/run-tests.md +3 -3
- package/docs/guides/test/snapshot.md +3 -3
- package/docs/guides/test/update-snapshots.md +1 -1
- package/docs/guides/util/version.md +1 -1
- package/docs/installation.md +4 -4
- package/docs/runtime/debugger.md +3 -3
- package/docs/runtime/nodejs-apis.md +1 -1
- package/docs/test/dom.md +1 -1
- package/docs/typescript.md +7 -6
- package/extensions.d.ts +31 -0
- package/fetch.d.ts +62 -159
- package/ffi.d.ts +1084 -1108
- package/globals.d.ts +1721 -1949
- package/html-rewriter.d.ts +146 -151
- package/index.d.ts +13 -11
- package/jsc.d.ts +216 -230
- package/overrides.d.ts +106 -63
- package/package.json +39 -31
- package/s3.d.ts +825 -0
- package/sqlite.d.ts +1143 -1172
- package/test.d.ts +2130 -2241
- package/wasm.d.ts +190 -288
- package/ambient.d.ts +0 -31
package/sqlite.d.ts
CHANGED
|
@@ -24,1220 +24,1191 @@
|
|
|
24
24
|
* | `null` | `NULL` |
|
|
25
25
|
*/
|
|
26
26
|
declare module "bun:sqlite" {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
27
|
+
export class Database implements Disposable {
|
|
28
|
+
/**
|
|
29
|
+
* Open or create a SQLite3 database
|
|
30
|
+
*
|
|
31
|
+
* @param filename The filename of the database to open. Pass an empty string (`""`) or `":memory:"` or undefined for an in-memory database.
|
|
32
|
+
* @param options defaults to `{readwrite: true, create: true}`. If a number, then it's treated as `SQLITE_OPEN_*` constant flags.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* const db = new Database("mydb.sqlite");
|
|
38
|
+
* db.run("CREATE TABLE foo (bar TEXT)");
|
|
39
|
+
* db.run("INSERT INTO foo VALUES (?)", ["baz"]);
|
|
40
|
+
* console.log(db.query("SELECT * FROM foo").all());
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* Open an in-memory database
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* const db = new Database(":memory:");
|
|
49
|
+
* db.run("CREATE TABLE foo (bar TEXT)");
|
|
50
|
+
* db.run("INSERT INTO foo VALUES (?)", ["hiiiiii"]);
|
|
51
|
+
* console.log(db.query("SELECT * FROM foo").all());
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
*
|
|
56
|
+
* Open read-only
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const db = new Database("mydb.sqlite", {readonly: true});
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
constructor(
|
|
63
|
+
filename?: string,
|
|
64
|
+
options?:
|
|
65
|
+
| number
|
|
66
|
+
| {
|
|
67
|
+
/**
|
|
68
|
+
* Open the database as read-only (no write operations, no create).
|
|
69
|
+
*
|
|
70
|
+
* Equivalent to {@link constants.SQLITE_OPEN_READONLY}
|
|
71
|
+
*/
|
|
72
|
+
readonly?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Allow creating a new database
|
|
75
|
+
*
|
|
76
|
+
* Equivalent to {@link constants.SQLITE_OPEN_CREATE}
|
|
77
|
+
*/
|
|
78
|
+
create?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Open the database as read-write
|
|
81
|
+
*
|
|
82
|
+
* Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
|
|
83
|
+
*/
|
|
84
|
+
readwrite?: boolean;
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
/**
|
|
87
|
+
* When set to `true`, integers are returned as `bigint` types.
|
|
88
|
+
*
|
|
89
|
+
* When set to `false`, integers are returned as `number` types and truncated to 52 bits.
|
|
90
|
+
*
|
|
91
|
+
* @default false
|
|
92
|
+
* @since v1.1.14
|
|
93
|
+
*/
|
|
94
|
+
safeIntegers?: boolean;
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
96
|
+
/**
|
|
97
|
+
* When set to `false` or `undefined`:
|
|
98
|
+
* - Queries missing bound parameters will NOT throw an error
|
|
99
|
+
* - Bound named parameters in JavaScript need to exactly match the SQL query.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const db = new Database(":memory:", { strict: false });
|
|
104
|
+
* db.run("INSERT INTO foo (name) VALUES ($name)", { $name: "foo" });
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* When set to `true`:
|
|
108
|
+
* - Queries missing bound parameters will throw an error
|
|
109
|
+
* - Bound named parameters in JavaScript no longer need to be `$`, `:`, or `@`. The SQL query will remain prefixed.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const db = new Database(":memory:", { strict: true });
|
|
114
|
+
* db.run("INSERT INTO foo (name) VALUES ($name)", { name: "foo" });
|
|
115
|
+
* ```
|
|
116
|
+
* @since v1.1.14
|
|
117
|
+
*/
|
|
118
|
+
strict?: boolean;
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
122
|
+
/**
|
|
123
|
+
* This is an alias of `new Database()`
|
|
124
|
+
*
|
|
125
|
+
* See {@link Database}
|
|
126
|
+
*/
|
|
127
|
+
static open(
|
|
128
|
+
filename: string,
|
|
129
|
+
options?:
|
|
130
|
+
| number
|
|
131
|
+
| {
|
|
132
|
+
/**
|
|
133
|
+
* Open the database as read-only (no write operations, no create).
|
|
134
|
+
*
|
|
135
|
+
* Equivalent to {@link constants.SQLITE_OPEN_READONLY}
|
|
136
|
+
*/
|
|
137
|
+
readonly?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Allow creating a new database
|
|
140
|
+
*
|
|
141
|
+
* Equivalent to {@link constants.SQLITE_OPEN_CREATE}
|
|
142
|
+
*/
|
|
143
|
+
create?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Open the database as read-write
|
|
146
|
+
*
|
|
147
|
+
* Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
|
|
148
|
+
*/
|
|
149
|
+
readwrite?: boolean;
|
|
150
|
+
},
|
|
151
|
+
): Database;
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
...bindings: ParamsType[]
|
|
205
|
-
): Changes;
|
|
206
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Execute a SQL query **without returning any results**.
|
|
155
|
+
*
|
|
156
|
+
* This does not cache the query, so if you want to run a query multiple times, you should use {@link prepare} instead.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* db.run("CREATE TABLE foo (bar TEXT)");
|
|
161
|
+
* db.run("INSERT INTO foo VALUES (?)", ["baz"]);
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* Useful for queries like:
|
|
165
|
+
* - `CREATE TABLE`
|
|
166
|
+
* - `INSERT INTO`
|
|
167
|
+
* - `UPDATE`
|
|
168
|
+
* - `DELETE FROM`
|
|
169
|
+
* - `DROP TABLE`
|
|
170
|
+
* - `PRAGMA`
|
|
171
|
+
* - `ATTACH DATABASE`
|
|
172
|
+
* - `DETACH DATABASE`
|
|
173
|
+
* - `REINDEX`
|
|
174
|
+
* - `VACUUM`
|
|
175
|
+
* - `EXPLAIN ANALYZE`
|
|
176
|
+
* - `CREATE INDEX`
|
|
177
|
+
* - `CREATE TRIGGER`
|
|
178
|
+
* - `CREATE VIEW`
|
|
179
|
+
* - `CREATE VIRTUAL TABLE`
|
|
180
|
+
* - `CREATE TEMPORARY TABLE`
|
|
181
|
+
*
|
|
182
|
+
* @param sql The SQL query to run
|
|
183
|
+
*
|
|
184
|
+
* @param bindings Optional bindings for the query
|
|
185
|
+
*
|
|
186
|
+
* @returns `Database` instance
|
|
187
|
+
*
|
|
188
|
+
* Under the hood, this calls `sqlite3_prepare_v3` followed by `sqlite3_step` and `sqlite3_finalize`.
|
|
189
|
+
*
|
|
190
|
+
* * The following types can be used when binding parameters:
|
|
191
|
+
*
|
|
192
|
+
* | JavaScript type | SQLite type |
|
|
193
|
+
* | -------------- | ----------- |
|
|
194
|
+
* | `string` | `TEXT` |
|
|
195
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
196
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
197
|
+
* | `Uint8Array` | `BLOB` |
|
|
198
|
+
* | `Buffer` | `BLOB` |
|
|
199
|
+
* | `bigint` | `INTEGER` |
|
|
200
|
+
* | `null` | `NULL` |
|
|
201
|
+
*/
|
|
202
|
+
run<ParamsType extends SQLQueryBindings[]>(sqlQuery: string, ...bindings: ParamsType[]): Changes;
|
|
203
|
+
/**
|
|
207
204
|
This is an alias of {@link Database.prototype.run}
|
|
208
205
|
*/
|
|
209
|
-
|
|
210
|
-
sqlQuery: string,
|
|
211
|
-
...bindings: ParamsType[]
|
|
212
|
-
): Changes;
|
|
206
|
+
exec<ParamsType extends SQLQueryBindings[]>(sqlQuery: string, ...bindings: ParamsType[]): Changes;
|
|
213
207
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Compile a SQL query and return a {@link Statement} object. This is the
|
|
210
|
+
* same as {@link prepare} except that it caches the compiled query.
|
|
211
|
+
*
|
|
212
|
+
* This **does not execute** the query, but instead prepares it for later
|
|
213
|
+
* execution and caches the compiled query if possible.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* // compile the query
|
|
218
|
+
* const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
|
|
219
|
+
* // run the query
|
|
220
|
+
* stmt.all("baz");
|
|
221
|
+
*
|
|
222
|
+
* // run the query again
|
|
223
|
+
* stmt.all();
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @param sql The SQL query to compile
|
|
227
|
+
*
|
|
228
|
+
* @returns `Statment` instance
|
|
229
|
+
*
|
|
230
|
+
* Under the hood, this calls `sqlite3_prepare_v3`.
|
|
231
|
+
*/
|
|
232
|
+
query<ReturnType, ParamsType extends SQLQueryBindings | SQLQueryBindings[]>(
|
|
233
|
+
sqlQuery: string,
|
|
234
|
+
): // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
|
|
235
|
+
Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
|
|
242
236
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
params?: ParamsType,
|
|
269
|
-
): // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
|
|
270
|
-
Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
|
|
237
|
+
/**
|
|
238
|
+
* Compile a SQL query and return a {@link Statement} object.
|
|
239
|
+
*
|
|
240
|
+
* This does not cache the compiled query and does not execute the query.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* // compile the query
|
|
245
|
+
* const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
|
|
246
|
+
* // run the query
|
|
247
|
+
* stmt.all("baz");
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @param sql The SQL query to compile
|
|
251
|
+
* @param params Optional bindings for the query
|
|
252
|
+
*
|
|
253
|
+
* @returns `Statment` instance
|
|
254
|
+
*
|
|
255
|
+
* Under the hood, this calls `sqlite3_prepare_v3`.
|
|
256
|
+
*/
|
|
257
|
+
prepare<ReturnType, ParamsType extends SQLQueryBindings | SQLQueryBindings[]>(
|
|
258
|
+
sqlQuery: string,
|
|
259
|
+
params?: ParamsType,
|
|
260
|
+
): // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
|
|
261
|
+
Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
|
|
271
262
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Is the database in a transaction?
|
|
265
|
+
*
|
|
266
|
+
* @returns `true` if the database is in a transaction, `false` otherwise
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* db.run("CREATE TABLE foo (bar TEXT)");
|
|
271
|
+
* db.run("INSERT INTO foo VALUES (?)", ["baz"]);
|
|
272
|
+
* db.run("BEGIN");
|
|
273
|
+
* db.run("INSERT INTO foo VALUES (?)", ["qux"]);
|
|
274
|
+
* console.log(db.inTransaction());
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
get inTransaction(): boolean;
|
|
287
278
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Close the database connection.
|
|
281
|
+
*
|
|
282
|
+
* It is safe to call this method multiple times. If the database is already
|
|
283
|
+
* closed, this is a no-op. Running queries after the database has been
|
|
284
|
+
* closed will throw an error.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* db.close();
|
|
289
|
+
* ```
|
|
290
|
+
* This is called automatically when the database instance is garbage collected.
|
|
291
|
+
*
|
|
292
|
+
* Internally, this calls `sqlite3_close_v2`.
|
|
293
|
+
*/
|
|
294
|
+
close(
|
|
295
|
+
/**
|
|
296
|
+
* If `true`, then the database will throw an error if it is in use
|
|
297
|
+
* @default false
|
|
298
|
+
*
|
|
299
|
+
* When true, this calls `sqlite3_close` instead of `sqlite3_close_v2`.
|
|
300
|
+
*
|
|
301
|
+
* Learn more about this in the [sqlite3 documentation](https://www.sqlite.org/c3ref/close.html).
|
|
302
|
+
*
|
|
303
|
+
* Bun will automatically call close by default when the database instance is garbage collected.
|
|
304
|
+
* In The future, Bun may default `throwOnError` to be true but for backwards compatibility, it is false by default.
|
|
305
|
+
*/
|
|
306
|
+
throwOnError?: boolean,
|
|
307
|
+
): void;
|
|
317
308
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
309
|
+
/**
|
|
310
|
+
* The filename passed when `new Database()` was called
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* const db = new Database("mydb.sqlite");
|
|
314
|
+
* console.log(db.filename);
|
|
315
|
+
* // => "mydb.sqlite"
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
readonly filename: string;
|
|
328
319
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
320
|
+
/**
|
|
321
|
+
* The underlying `sqlite3` database handle
|
|
322
|
+
*
|
|
323
|
+
* In native code, this is not a file descriptor, but an index into an array of database handles
|
|
324
|
+
*/
|
|
325
|
+
readonly handle: number;
|
|
335
326
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Load a SQLite3 extension
|
|
329
|
+
*
|
|
330
|
+
* macOS requires a custom SQLite3 library to be linked because the Apple build of SQLite for macOS disables loading extensions. See {@link Database.setCustomSQLite}
|
|
331
|
+
*
|
|
332
|
+
* Bun chooses the Apple build of SQLite on macOS because it brings a ~50% performance improvement.
|
|
333
|
+
*
|
|
334
|
+
* @param extension name/path of the extension to load
|
|
335
|
+
* @param entryPoint optional entry point of the extension
|
|
336
|
+
*/
|
|
337
|
+
loadExtension(extension: string, entryPoint?: string): void;
|
|
347
338
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Change the dynamic library path to SQLite
|
|
341
|
+
*
|
|
342
|
+
* @note macOS-only
|
|
343
|
+
*
|
|
344
|
+
* This only works before SQLite is loaded, so
|
|
345
|
+
* that's before you call `new Database()`.
|
|
346
|
+
*
|
|
347
|
+
* It can only be run once because this will load
|
|
348
|
+
* the SQLite library into the process.
|
|
349
|
+
*
|
|
350
|
+
* @param path The path to the SQLite library
|
|
351
|
+
*/
|
|
352
|
+
static setCustomSQLite(path: string): boolean;
|
|
362
353
|
|
|
363
|
-
|
|
354
|
+
[Symbol.dispose](): void;
|
|
364
355
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Creates a function that always runs inside a transaction. When the
|
|
358
|
+
* function is invoked, it will begin a new transaction. When the function
|
|
359
|
+
* returns, the transaction will be committed. If an exception is thrown,
|
|
360
|
+
* the transaction will be rolled back (and the exception will propagate as
|
|
361
|
+
* usual).
|
|
362
|
+
*
|
|
363
|
+
* @param insideTransaction The callback which runs inside a transaction
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* // setup
|
|
368
|
+
* import { Database } from "bun:sqlite";
|
|
369
|
+
* const db = Database.open(":memory:");
|
|
370
|
+
* db.exec(
|
|
371
|
+
* "CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)"
|
|
372
|
+
* );
|
|
373
|
+
*
|
|
374
|
+
* const insert = db.prepare("INSERT INTO cats (name, age) VALUES ($name, $age)");
|
|
375
|
+
* const insertMany = db.transaction((cats) => {
|
|
376
|
+
* for (const cat of cats) insert.run(cat);
|
|
377
|
+
* });
|
|
378
|
+
*
|
|
379
|
+
* insertMany([
|
|
380
|
+
* { $name: "Joey", $age: 2 },
|
|
381
|
+
* { $name: "Sally", $age: 4 },
|
|
382
|
+
* { $name: "Junior", $age: 1 },
|
|
383
|
+
* ]);
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
transaction(insideTransaction: (...args: any) => void): CallableFunction & {
|
|
387
|
+
/**
|
|
388
|
+
* uses "BEGIN DEFERRED"
|
|
389
|
+
*/
|
|
390
|
+
deferred: (...args: any) => void;
|
|
391
|
+
/**
|
|
392
|
+
* uses "BEGIN IMMEDIATE"
|
|
393
|
+
*/
|
|
394
|
+
immediate: (...args: any) => void;
|
|
395
|
+
/**
|
|
396
|
+
* uses "BEGIN EXCLUSIVE"
|
|
397
|
+
*/
|
|
398
|
+
exclusive: (...args: any) => void;
|
|
399
|
+
};
|
|
409
400
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
401
|
+
/**
|
|
402
|
+
* Save the database to an in-memory {@link Buffer} object.
|
|
403
|
+
*
|
|
404
|
+
* Internally, this calls `sqlite3_serialize`.
|
|
405
|
+
*
|
|
406
|
+
* @param name Name to save the database as @default "main"
|
|
407
|
+
* @returns Buffer containing the serialized database
|
|
408
|
+
*/
|
|
409
|
+
serialize(name?: string): Buffer;
|
|
419
410
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
serialized: NodeJS.TypedArray | ArrayBufferLike,
|
|
489
|
-
isReadOnly?: boolean,
|
|
490
|
-
): Database;
|
|
411
|
+
/**
|
|
412
|
+
* Load a serialized SQLite3 database
|
|
413
|
+
*
|
|
414
|
+
* Internally, this calls `sqlite3_deserialize`.
|
|
415
|
+
*
|
|
416
|
+
* @param serialized Data to load
|
|
417
|
+
* @returns `Database` instance
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```ts
|
|
421
|
+
* test("supports serialize/deserialize", () => {
|
|
422
|
+
* const db = Database.open(":memory:");
|
|
423
|
+
* db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");
|
|
424
|
+
* db.exec('INSERT INTO test (name) VALUES ("Hello")');
|
|
425
|
+
* db.exec('INSERT INTO test (name) VALUES ("World")');
|
|
426
|
+
*
|
|
427
|
+
* const input = db.serialize();
|
|
428
|
+
* const db2 = new Database(input);
|
|
429
|
+
*
|
|
430
|
+
* const stmt = db2.prepare("SELECT * FROM test");
|
|
431
|
+
* expect(JSON.stringify(stmt.get())).toBe(
|
|
432
|
+
* JSON.stringify({
|
|
433
|
+
* id: 1,
|
|
434
|
+
* name: "Hello",
|
|
435
|
+
* }),
|
|
436
|
+
* );
|
|
437
|
+
*
|
|
438
|
+
* expect(JSON.stringify(stmt.all())).toBe(
|
|
439
|
+
* JSON.stringify([
|
|
440
|
+
* {
|
|
441
|
+
* id: 1,
|
|
442
|
+
* name: "Hello",
|
|
443
|
+
* },
|
|
444
|
+
* {
|
|
445
|
+
* id: 2,
|
|
446
|
+
* name: "World",
|
|
447
|
+
* },
|
|
448
|
+
* ]),
|
|
449
|
+
* );
|
|
450
|
+
* db2.exec("insert into test (name) values ('foo')");
|
|
451
|
+
* expect(JSON.stringify(stmt.all())).toBe(
|
|
452
|
+
* JSON.stringify([
|
|
453
|
+
* {
|
|
454
|
+
* id: 1,
|
|
455
|
+
* name: "Hello",
|
|
456
|
+
* },
|
|
457
|
+
* {
|
|
458
|
+
* id: 2,
|
|
459
|
+
* name: "World",
|
|
460
|
+
* },
|
|
461
|
+
* {
|
|
462
|
+
* id: 3,
|
|
463
|
+
* name: "foo",
|
|
464
|
+
* },
|
|
465
|
+
* ]),
|
|
466
|
+
* );
|
|
467
|
+
*
|
|
468
|
+
* const db3 = Database.deserialize(input, true);
|
|
469
|
+
* try {
|
|
470
|
+
* db3.exec("insert into test (name) values ('foo')");
|
|
471
|
+
* throw new Error("Expected error");
|
|
472
|
+
* } catch (e) {
|
|
473
|
+
* expect(e.message).toBe("attempt to write a readonly database");
|
|
474
|
+
* }
|
|
475
|
+
* });
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
static deserialize(serialized: NodeJS.TypedArray | ArrayBufferLike, isReadOnly?: boolean): Database;
|
|
491
479
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
strict?: boolean;
|
|
565
|
-
safeIntegers?: boolean;
|
|
566
|
-
},
|
|
567
|
-
): Database;
|
|
480
|
+
/**
|
|
481
|
+
* Load a serialized SQLite3 database. This version enables you to specify
|
|
482
|
+
* additional options such as `strict` to put the database into strict mode.
|
|
483
|
+
*
|
|
484
|
+
* Internally, this calls `sqlite3_deserialize`.
|
|
485
|
+
*
|
|
486
|
+
* @param serialized Data to load
|
|
487
|
+
* @returns `Database` instance
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```ts
|
|
491
|
+
* test("supports serialize/deserialize", () => {
|
|
492
|
+
* const db = Database.open(":memory:");
|
|
493
|
+
* db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");
|
|
494
|
+
* db.exec('INSERT INTO test (name) VALUES ("Hello")');
|
|
495
|
+
* db.exec('INSERT INTO test (name) VALUES ("World")');
|
|
496
|
+
*
|
|
497
|
+
* const input = db.serialize();
|
|
498
|
+
* const db2 = Database.deserialize(input, { strict: true });
|
|
499
|
+
*
|
|
500
|
+
* const stmt = db2.prepare("SELECT * FROM test");
|
|
501
|
+
* expect(JSON.stringify(stmt.get())).toBe(
|
|
502
|
+
* JSON.stringify({
|
|
503
|
+
* id: 1,
|
|
504
|
+
* name: "Hello",
|
|
505
|
+
* }),
|
|
506
|
+
* );
|
|
507
|
+
*
|
|
508
|
+
* expect(JSON.stringify(stmt.all())).toBe(
|
|
509
|
+
* JSON.stringify([
|
|
510
|
+
* {
|
|
511
|
+
* id: 1,
|
|
512
|
+
* name: "Hello",
|
|
513
|
+
* },
|
|
514
|
+
* {
|
|
515
|
+
* id: 2,
|
|
516
|
+
* name: "World",
|
|
517
|
+
* },
|
|
518
|
+
* ]),
|
|
519
|
+
* );
|
|
520
|
+
* db2.exec("insert into test (name) values ($foo)", { foo: "baz" });
|
|
521
|
+
* expect(JSON.stringify(stmt.all())).toBe(
|
|
522
|
+
* JSON.stringify([
|
|
523
|
+
* {
|
|
524
|
+
* id: 1,
|
|
525
|
+
* name: "Hello",
|
|
526
|
+
* },
|
|
527
|
+
* {
|
|
528
|
+
* id: 2,
|
|
529
|
+
* name: "World",
|
|
530
|
+
* },
|
|
531
|
+
* {
|
|
532
|
+
* id: 3,
|
|
533
|
+
* name: "baz",
|
|
534
|
+
* },
|
|
535
|
+
* ]),
|
|
536
|
+
* );
|
|
537
|
+
*
|
|
538
|
+
* const db3 = Database.deserialize(input, { readonly: true, strict: true });
|
|
539
|
+
* try {
|
|
540
|
+
* db3.exec("insert into test (name) values ($foo)", { foo: "baz" });
|
|
541
|
+
* throw new Error("Expected error");
|
|
542
|
+
* } catch (e) {
|
|
543
|
+
* expect(e.message).toBe("attempt to write a readonly database");
|
|
544
|
+
* }
|
|
545
|
+
* });
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
static deserialize(
|
|
549
|
+
serialized: NodeJS.TypedArray | ArrayBufferLike,
|
|
550
|
+
options?: { readonly?: boolean; strict?: boolean; safeIntegers?: boolean },
|
|
551
|
+
): Database;
|
|
568
552
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
op: number,
|
|
581
|
-
arg?: ArrayBufferView | number,
|
|
582
|
-
): number;
|
|
583
|
-
}
|
|
553
|
+
/**
|
|
554
|
+
* See `sqlite3_file_control` for more information.
|
|
555
|
+
* @link https://www.sqlite.org/c3ref/file_control.html
|
|
556
|
+
*/
|
|
557
|
+
fileControl(op: number, arg?: ArrayBufferView | number): number;
|
|
558
|
+
/**
|
|
559
|
+
* See `sqlite3_file_control` for more information.
|
|
560
|
+
* @link https://www.sqlite.org/c3ref/file_control.html
|
|
561
|
+
*/
|
|
562
|
+
fileControl(zDbName: string, op: number, arg?: ArrayBufferView | number): number;
|
|
563
|
+
}
|
|
584
564
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
*
|
|
619
|
-
* This is used internally by the {@link Database} class. Probably you don't need to call this yourself.
|
|
620
|
-
*/
|
|
621
|
-
constructor(nativeHandle: any);
|
|
565
|
+
/**
|
|
566
|
+
* A prepared statement.
|
|
567
|
+
*
|
|
568
|
+
* This is returned by {@link Database.prepare} and {@link Database.query}.
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
573
|
+
* stmt.all("baz");
|
|
574
|
+
* // => [{bar: "baz"}]
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```ts
|
|
579
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
580
|
+
* stmt.get("baz");
|
|
581
|
+
* // => {bar: "baz"}
|
|
582
|
+
* ```
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```ts
|
|
586
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
587
|
+
* stmt.run("baz");
|
|
588
|
+
* // => undefined
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
export class Statement<ReturnType = unknown, ParamsType extends SQLQueryBindings[] = any[]> implements Disposable {
|
|
592
|
+
/**
|
|
593
|
+
* Creates a new prepared statement from native code.
|
|
594
|
+
*
|
|
595
|
+
* This is used internally by the {@link Database} class. Probably you don't need to call this yourself.
|
|
596
|
+
*/
|
|
597
|
+
constructor(nativeHandle: any);
|
|
622
598
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
599
|
+
/**
|
|
600
|
+
* Execute the prepared statement and return all results as objects.
|
|
601
|
+
*
|
|
602
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```ts
|
|
606
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
607
|
+
*
|
|
608
|
+
* stmt.all("baz");
|
|
609
|
+
* // => [{bar: "baz"}]
|
|
610
|
+
*
|
|
611
|
+
* stmt.all();
|
|
612
|
+
* // => []
|
|
613
|
+
*
|
|
614
|
+
* stmt.all("foo");
|
|
615
|
+
* // => [{bar: "foo"}]
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
618
|
+
all(...params: ParamsType): ReturnType[];
|
|
643
619
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
620
|
+
/**
|
|
621
|
+
* Execute the prepared statement and return **the first** result.
|
|
622
|
+
*
|
|
623
|
+
* If no result is returned, this returns `null`.
|
|
624
|
+
*
|
|
625
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* ```ts
|
|
629
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
630
|
+
*
|
|
631
|
+
* stmt.get("baz");
|
|
632
|
+
* // => {bar: "baz"}
|
|
633
|
+
*
|
|
634
|
+
* stmt.get();
|
|
635
|
+
* // => null
|
|
636
|
+
*
|
|
637
|
+
* stmt.get("foo");
|
|
638
|
+
* // => {bar: "foo"}
|
|
639
|
+
* ```
|
|
640
|
+
*
|
|
641
|
+
* The following types can be used when binding parameters:
|
|
642
|
+
*
|
|
643
|
+
* | JavaScript type | SQLite type |
|
|
644
|
+
* | -------------- | ----------- |
|
|
645
|
+
* | `string` | `TEXT` |
|
|
646
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
647
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
648
|
+
* | `Uint8Array` | `BLOB` |
|
|
649
|
+
* | `Buffer` | `BLOB` |
|
|
650
|
+
* | `bigint` | `INTEGER` |
|
|
651
|
+
* | `null` | `NULL` |
|
|
652
|
+
*/
|
|
653
|
+
get(...params: ParamsType): ReturnType | null;
|
|
678
654
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
655
|
+
/**
|
|
656
|
+
* Execute the prepared statement and return an
|
|
657
|
+
*
|
|
658
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
659
|
+
*
|
|
660
|
+
*/
|
|
661
|
+
iterate(...params: ParamsType): IterableIterator<ReturnType>;
|
|
662
|
+
[Symbol.iterator](): IterableIterator<ReturnType>;
|
|
687
663
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
664
|
+
/**
|
|
665
|
+
* Execute the prepared statement. This returns `undefined`.
|
|
666
|
+
*
|
|
667
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```ts
|
|
671
|
+
* const stmt = db.prepare("UPDATE foo SET bar = ?");
|
|
672
|
+
* stmt.run("baz");
|
|
673
|
+
* // => undefined
|
|
674
|
+
*
|
|
675
|
+
* stmt.run();
|
|
676
|
+
* // => undefined
|
|
677
|
+
*
|
|
678
|
+
* stmt.run("foo");
|
|
679
|
+
* // => undefined
|
|
680
|
+
* ```
|
|
681
|
+
*
|
|
682
|
+
* The following types can be used when binding parameters:
|
|
683
|
+
*
|
|
684
|
+
* | JavaScript type | SQLite type |
|
|
685
|
+
* | -------------- | ----------- |
|
|
686
|
+
* | `string` | `TEXT` |
|
|
687
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
688
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
689
|
+
* | `Uint8Array` | `BLOB` |
|
|
690
|
+
* | `Buffer` | `BLOB` |
|
|
691
|
+
* | `bigint` | `INTEGER` |
|
|
692
|
+
* | `null` | `NULL` |
|
|
693
|
+
*/
|
|
694
|
+
run(...params: ParamsType): Changes;
|
|
719
695
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
...params: ParamsType
|
|
760
|
-
): Array<Array<string | bigint | number | boolean | Uint8Array>>;
|
|
696
|
+
/**
|
|
697
|
+
* Execute the prepared statement and return the results as an array of arrays.
|
|
698
|
+
*
|
|
699
|
+
* In Bun v0.6.7 and earlier, this method returned `null` if there were no
|
|
700
|
+
* results instead of `[]`. This was changed in v0.6.8 to align
|
|
701
|
+
* more with what people expect.
|
|
702
|
+
*
|
|
703
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```ts
|
|
707
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
708
|
+
*
|
|
709
|
+
* stmt.values("baz");
|
|
710
|
+
* // => [['baz']]
|
|
711
|
+
*
|
|
712
|
+
* stmt.values();
|
|
713
|
+
* // => [['baz']]
|
|
714
|
+
*
|
|
715
|
+
* stmt.values("foo");
|
|
716
|
+
* // => [['foo']]
|
|
717
|
+
*
|
|
718
|
+
* stmt.values("not-found");
|
|
719
|
+
* // => []
|
|
720
|
+
* ```
|
|
721
|
+
*
|
|
722
|
+
* The following types can be used when binding parameters:
|
|
723
|
+
*
|
|
724
|
+
* | JavaScript type | SQLite type |
|
|
725
|
+
* | ---------------|-------------|
|
|
726
|
+
* | `string` | `TEXT` |
|
|
727
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
728
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
729
|
+
* | `Uint8Array` | `BLOB` |
|
|
730
|
+
* | `Buffer` | `BLOB` |
|
|
731
|
+
* | `bigint` | `INTEGER` |
|
|
732
|
+
* | `null` | `NULL` |
|
|
733
|
+
*/
|
|
734
|
+
values(...params: ParamsType): Array<Array<string | bigint | number | boolean | Uint8Array>>;
|
|
761
735
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
736
|
+
/**
|
|
737
|
+
* The names of the columns returned by the prepared statement.
|
|
738
|
+
* @example
|
|
739
|
+
* ```ts
|
|
740
|
+
* const stmt = db.prepare("SELECT bar FROM foo WHERE bar = ?");
|
|
741
|
+
*
|
|
742
|
+
* console.log(stmt.columnNames);
|
|
743
|
+
* // => ["bar"]
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
readonly columnNames: string[];
|
|
773
747
|
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
748
|
+
/**
|
|
749
|
+
* The number of parameters expected in the prepared statement.
|
|
750
|
+
* @example
|
|
751
|
+
* ```ts
|
|
752
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
753
|
+
* console.log(stmt.paramsCount);
|
|
754
|
+
* // => 1
|
|
755
|
+
* ```
|
|
756
|
+
* @example
|
|
757
|
+
* ```ts
|
|
758
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?");
|
|
759
|
+
* console.log(stmt.paramsCount);
|
|
760
|
+
* // => 2
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
readonly paramsCount: number;
|
|
790
764
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
765
|
+
/**
|
|
766
|
+
* Finalize the prepared statement, freeing the resources used by the
|
|
767
|
+
* statement and preventing it from being executed again.
|
|
768
|
+
*
|
|
769
|
+
* This is called automatically when the prepared statement is garbage collected.
|
|
770
|
+
*
|
|
771
|
+
* It is safe to call this multiple times. Calling this on a finalized
|
|
772
|
+
* statement has no effect.
|
|
773
|
+
*
|
|
774
|
+
* Internally, this calls `sqlite3_finalize`.
|
|
775
|
+
*/
|
|
776
|
+
finalize(): void;
|
|
803
777
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
778
|
+
/**
|
|
779
|
+
* Calls {@link finalize} if it wasn't already called.
|
|
780
|
+
*/
|
|
781
|
+
[Symbol.dispose](): void;
|
|
808
782
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
783
|
+
/**
|
|
784
|
+
* Return the expanded SQL string for the prepared statement.
|
|
785
|
+
*
|
|
786
|
+
* Internally, this calls `sqlite3_expanded_sql()` on the underlying `sqlite3_stmt`.
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```ts
|
|
790
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?", "baz");
|
|
791
|
+
* console.log(stmt.toString());
|
|
792
|
+
* // => "SELECT * FROM foo WHERE bar = 'baz'"
|
|
793
|
+
* console.log(stmt);
|
|
794
|
+
* // => "SELECT * FROM foo WHERE bar = 'baz'"
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
797
|
+
toString(): string;
|
|
824
798
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
799
|
+
/**
|
|
800
|
+
*
|
|
801
|
+
* Make {@link get} and {@link all} return an instance of the provided
|
|
802
|
+
* `Class` instead of the default `Object`.
|
|
803
|
+
*
|
|
804
|
+
* @param Class A class to use
|
|
805
|
+
* @returns The same statement instance, modified to return an instance of `Class`
|
|
806
|
+
*
|
|
807
|
+
* This lets you attach methods, getters, and setters to the returned
|
|
808
|
+
* objects.
|
|
809
|
+
*
|
|
810
|
+
* For performance reasons, constructors for classes are not called, which means
|
|
811
|
+
* initializers will not be called and private fields will not be
|
|
812
|
+
* accessible.
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
*
|
|
816
|
+
* ## Custom class
|
|
817
|
+
* ```ts
|
|
818
|
+
* class User {
|
|
819
|
+
* rawBirthdate: string;
|
|
820
|
+
* get birthdate() {
|
|
821
|
+
* return new Date(this.rawBirthdate);
|
|
822
|
+
* }
|
|
823
|
+
* }
|
|
824
|
+
*
|
|
825
|
+
* const db = new Database(":memory:");
|
|
826
|
+
* db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, rawBirthdate TEXT)");
|
|
827
|
+
* db.run("INSERT INTO users (rawBirthdate) VALUES ('1995-12-19')");
|
|
828
|
+
* const query = db.query("SELECT * FROM users");
|
|
829
|
+
* query.as(User);
|
|
830
|
+
* const user = query.get();
|
|
831
|
+
* console.log(user.birthdate);
|
|
832
|
+
* // => Date(1995, 12, 19)
|
|
833
|
+
* ```
|
|
834
|
+
*/
|
|
835
|
+
as<T = unknown>(Class: new (...args: any[]) => T): Statement<T, ParamsType>;
|
|
862
836
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
837
|
+
/**
|
|
838
|
+
* Native object representing the underlying `sqlite3_stmt`
|
|
839
|
+
*
|
|
840
|
+
* This is left untyped because the ABI of the native bindings may change at any time.
|
|
841
|
+
*/
|
|
842
|
+
readonly native: any;
|
|
843
|
+
}
|
|
870
844
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
845
|
+
/**
|
|
846
|
+
* Constants from `sqlite3.h`
|
|
847
|
+
*
|
|
848
|
+
* This list isn't exhaustive, but some of the ones which are relevant
|
|
849
|
+
*/
|
|
850
|
+
export const constants: {
|
|
851
|
+
/**
|
|
852
|
+
* Open the database as read-only (no write operations, no create).
|
|
853
|
+
* @constant 0x00000001
|
|
854
|
+
*/
|
|
855
|
+
SQLITE_OPEN_READONLY: number;
|
|
856
|
+
/**
|
|
857
|
+
* Open the database for reading and writing
|
|
858
|
+
* @constant 0x00000002
|
|
859
|
+
*/
|
|
860
|
+
SQLITE_OPEN_READWRITE: number;
|
|
861
|
+
/**
|
|
862
|
+
* Allow creating a new database
|
|
863
|
+
* @constant 0x00000004
|
|
864
|
+
*/
|
|
865
|
+
SQLITE_OPEN_CREATE: number;
|
|
866
|
+
/**
|
|
867
|
+
* @constant 0x00000008
|
|
868
|
+
*/
|
|
869
|
+
SQLITE_OPEN_DELETEONCLOSE: number;
|
|
870
|
+
/**
|
|
871
|
+
* @constant 0x00000010
|
|
872
|
+
*/
|
|
873
|
+
SQLITE_OPEN_EXCLUSIVE: number;
|
|
874
|
+
/**
|
|
875
|
+
* @constant 0x00000020
|
|
876
|
+
*/
|
|
877
|
+
SQLITE_OPEN_AUTOPROXY: number;
|
|
878
|
+
/**
|
|
879
|
+
* @constant 0x00000040
|
|
880
|
+
*/
|
|
881
|
+
SQLITE_OPEN_URI: number;
|
|
882
|
+
/**
|
|
883
|
+
* @constant 0x00000080
|
|
884
|
+
*/
|
|
885
|
+
SQLITE_OPEN_MEMORY: number;
|
|
886
|
+
/**
|
|
887
|
+
* @constant 0x00000100
|
|
888
|
+
*/
|
|
889
|
+
SQLITE_OPEN_MAIN_DB: number;
|
|
890
|
+
/**
|
|
891
|
+
* @constant 0x00000200
|
|
892
|
+
*/
|
|
893
|
+
SQLITE_OPEN_TEMP_DB: number;
|
|
894
|
+
/**
|
|
895
|
+
* @constant 0x00000400
|
|
896
|
+
*/
|
|
897
|
+
SQLITE_OPEN_TRANSIENT_DB: number;
|
|
898
|
+
/**
|
|
899
|
+
* @constant 0x00000800
|
|
900
|
+
*/
|
|
901
|
+
SQLITE_OPEN_MAIN_JOURNAL: number;
|
|
902
|
+
/**
|
|
903
|
+
* @constant 0x00001000
|
|
904
|
+
*/
|
|
905
|
+
SQLITE_OPEN_TEMP_JOURNAL: number;
|
|
906
|
+
/**
|
|
907
|
+
* @constant 0x00002000
|
|
908
|
+
*/
|
|
909
|
+
SQLITE_OPEN_SUBJOURNAL: number;
|
|
910
|
+
/**
|
|
911
|
+
* @constant 0x00004000
|
|
912
|
+
*/
|
|
913
|
+
SQLITE_OPEN_SUPER_JOURNAL: number;
|
|
914
|
+
/**
|
|
915
|
+
* @constant 0x00008000
|
|
916
|
+
*/
|
|
917
|
+
SQLITE_OPEN_NOMUTEX: number;
|
|
918
|
+
/**
|
|
919
|
+
* @constant 0x00010000
|
|
920
|
+
*/
|
|
921
|
+
SQLITE_OPEN_FULLMUTEX: number;
|
|
922
|
+
/**
|
|
923
|
+
* @constant 0x00020000
|
|
924
|
+
*/
|
|
925
|
+
SQLITE_OPEN_SHAREDCACHE: number;
|
|
926
|
+
/**
|
|
927
|
+
* @constant 0x00040000
|
|
928
|
+
*/
|
|
929
|
+
SQLITE_OPEN_PRIVATECACHE: number;
|
|
930
|
+
/**
|
|
931
|
+
* @constant 0x00080000
|
|
932
|
+
*/
|
|
933
|
+
SQLITE_OPEN_WAL: number;
|
|
934
|
+
/**
|
|
935
|
+
* @constant 0x01000000
|
|
936
|
+
*/
|
|
937
|
+
SQLITE_OPEN_NOFOLLOW: number;
|
|
938
|
+
/**
|
|
939
|
+
* @constant 0x02000000
|
|
940
|
+
*/
|
|
941
|
+
SQLITE_OPEN_EXRESCODE: number;
|
|
942
|
+
/**
|
|
943
|
+
* @constant 0x01
|
|
944
|
+
*/
|
|
945
|
+
SQLITE_PREPARE_PERSISTENT: number;
|
|
946
|
+
/**
|
|
947
|
+
* @constant 0x02
|
|
948
|
+
*/
|
|
949
|
+
SQLITE_PREPARE_NORMALIZE: number;
|
|
950
|
+
/**
|
|
951
|
+
* @constant 0x04
|
|
952
|
+
*/
|
|
953
|
+
SQLITE_PREPARE_NO_VTAB: number;
|
|
980
954
|
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
955
|
+
/**
|
|
956
|
+
* @constant 1
|
|
957
|
+
*/
|
|
958
|
+
SQLITE_FCNTL_LOCKSTATE: number;
|
|
959
|
+
/**
|
|
960
|
+
* @constant 2
|
|
961
|
+
*/
|
|
962
|
+
SQLITE_FCNTL_GET_LOCKPROXYFILE: number;
|
|
963
|
+
/**
|
|
964
|
+
* @constant 3
|
|
965
|
+
*/
|
|
966
|
+
SQLITE_FCNTL_SET_LOCKPROXYFILE: number;
|
|
967
|
+
/**
|
|
968
|
+
* @constant 4
|
|
969
|
+
*/
|
|
970
|
+
SQLITE_FCNTL_LAST_ERRNO: number;
|
|
971
|
+
/**
|
|
972
|
+
* @constant 5
|
|
973
|
+
*/
|
|
974
|
+
SQLITE_FCNTL_SIZE_HINT: number;
|
|
975
|
+
/**
|
|
976
|
+
* @constant 6
|
|
977
|
+
*/
|
|
978
|
+
SQLITE_FCNTL_CHUNK_SIZE: number;
|
|
979
|
+
/**
|
|
980
|
+
* @constant 7
|
|
981
|
+
*/
|
|
982
|
+
SQLITE_FCNTL_FILE_POINTER: number;
|
|
983
|
+
/**
|
|
984
|
+
* @constant 8
|
|
985
|
+
*/
|
|
986
|
+
SQLITE_FCNTL_SYNC_OMITTED: number;
|
|
987
|
+
/**
|
|
988
|
+
* @constant 9
|
|
989
|
+
*/
|
|
990
|
+
SQLITE_FCNTL_WIN32_AV_RETRY: number;
|
|
991
|
+
/**
|
|
992
|
+
* @constant 10
|
|
993
|
+
*
|
|
994
|
+
* Control whether or not the WAL is persisted
|
|
995
|
+
* Some versions of macOS configure WAL to be persistent by default.
|
|
996
|
+
*
|
|
997
|
+
* You can change this with code like the below:
|
|
998
|
+
* ```ts
|
|
999
|
+
* import { Database } from "bun:sqlite";
|
|
1000
|
+
*
|
|
1001
|
+
* const db = Database.open("mydb.sqlite");
|
|
1002
|
+
* db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0);
|
|
1003
|
+
* // enable WAL
|
|
1004
|
+
* db.exec("PRAGMA journal_mode = WAL");
|
|
1005
|
+
* // .. do some work
|
|
1006
|
+
* db.close();
|
|
1007
|
+
* ```
|
|
1008
|
+
*
|
|
1009
|
+
*/
|
|
1010
|
+
SQLITE_FCNTL_PERSIST_WAL: number;
|
|
1011
|
+
/**
|
|
1012
|
+
* @constant 11
|
|
1013
|
+
*/
|
|
1014
|
+
SQLITE_FCNTL_OVERWRITE: number;
|
|
1015
|
+
/**
|
|
1016
|
+
* @constant 12
|
|
1017
|
+
*/
|
|
1018
|
+
SQLITE_FCNTL_VFSNAME: number;
|
|
1019
|
+
/**
|
|
1020
|
+
* @constant 13
|
|
1021
|
+
*/
|
|
1022
|
+
SQLITE_FCNTL_POWERSAFE_OVERWRITE: number;
|
|
1023
|
+
/**
|
|
1024
|
+
* @constant 14
|
|
1025
|
+
*/
|
|
1026
|
+
SQLITE_FCNTL_PRAGMA: number;
|
|
1027
|
+
/**
|
|
1028
|
+
* @constant 15
|
|
1029
|
+
*/
|
|
1030
|
+
SQLITE_FCNTL_BUSYHANDLER: number;
|
|
1031
|
+
/**
|
|
1032
|
+
* @constant 16
|
|
1033
|
+
*/
|
|
1034
|
+
SQLITE_FCNTL_TEMPFILENAME: number;
|
|
1035
|
+
/**
|
|
1036
|
+
* @constant 18
|
|
1037
|
+
*/
|
|
1038
|
+
SQLITE_FCNTL_MMAP_SIZE: number;
|
|
1039
|
+
/**
|
|
1040
|
+
* @constant 19
|
|
1041
|
+
*/
|
|
1042
|
+
SQLITE_FCNTL_TRACE: number;
|
|
1043
|
+
/**
|
|
1044
|
+
* @constant 20
|
|
1045
|
+
*/
|
|
1046
|
+
SQLITE_FCNTL_HAS_MOVED: number;
|
|
1047
|
+
/**
|
|
1048
|
+
* @constant 21
|
|
1049
|
+
*/
|
|
1050
|
+
SQLITE_FCNTL_SYNC: number;
|
|
1051
|
+
/**
|
|
1052
|
+
* @constant 22
|
|
1053
|
+
*/
|
|
1054
|
+
SQLITE_FCNTL_COMMIT_PHASETWO: number;
|
|
1055
|
+
/**
|
|
1056
|
+
* @constant 23
|
|
1057
|
+
*/
|
|
1058
|
+
SQLITE_FCNTL_WIN32_SET_HANDLE: number;
|
|
1059
|
+
/**
|
|
1060
|
+
* @constant 24
|
|
1061
|
+
*/
|
|
1062
|
+
SQLITE_FCNTL_WAL_BLOCK: number;
|
|
1063
|
+
/**
|
|
1064
|
+
* @constant 25
|
|
1065
|
+
*/
|
|
1066
|
+
SQLITE_FCNTL_ZIPVFS: number;
|
|
1067
|
+
/**
|
|
1068
|
+
* @constant 26
|
|
1069
|
+
*/
|
|
1070
|
+
SQLITE_FCNTL_RBU: number;
|
|
1071
|
+
/**
|
|
1072
|
+
* @constant 27
|
|
1073
|
+
*/
|
|
1074
|
+
SQLITE_FCNTL_VFS_POINTER: number;
|
|
1075
|
+
/**
|
|
1076
|
+
* @constant 28
|
|
1077
|
+
*/
|
|
1078
|
+
SQLITE_FCNTL_JOURNAL_POINTER: number;
|
|
1079
|
+
/**
|
|
1080
|
+
* @constant 29
|
|
1081
|
+
*/
|
|
1082
|
+
SQLITE_FCNTL_WIN32_GET_HANDLE: number;
|
|
1083
|
+
/**
|
|
1084
|
+
* @constant 30
|
|
1085
|
+
*/
|
|
1086
|
+
SQLITE_FCNTL_PDB: number;
|
|
1087
|
+
/**
|
|
1088
|
+
* @constant 31
|
|
1089
|
+
*/
|
|
1090
|
+
SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: number;
|
|
1091
|
+
/**
|
|
1092
|
+
* @constant 32
|
|
1093
|
+
*/
|
|
1094
|
+
SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: number;
|
|
1095
|
+
/**
|
|
1096
|
+
* @constant 33
|
|
1097
|
+
*/
|
|
1098
|
+
SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: number;
|
|
1099
|
+
/**
|
|
1100
|
+
* @constant 34
|
|
1101
|
+
*/
|
|
1102
|
+
SQLITE_FCNTL_LOCK_TIMEOUT: number;
|
|
1103
|
+
/**
|
|
1104
|
+
* @constant 35
|
|
1105
|
+
*/
|
|
1106
|
+
SQLITE_FCNTL_DATA_VERSION: number;
|
|
1107
|
+
/**
|
|
1108
|
+
* @constant 36
|
|
1109
|
+
*/
|
|
1110
|
+
SQLITE_FCNTL_SIZE_LIMIT: number;
|
|
1111
|
+
/**
|
|
1112
|
+
* @constant 37
|
|
1113
|
+
*/
|
|
1114
|
+
SQLITE_FCNTL_CKPT_DONE: number;
|
|
1115
|
+
/**
|
|
1116
|
+
* @constant 38
|
|
1117
|
+
*/
|
|
1118
|
+
SQLITE_FCNTL_RESERVE_BYTES: number;
|
|
1119
|
+
/**
|
|
1120
|
+
* @constant 39
|
|
1121
|
+
*/
|
|
1122
|
+
SQLITE_FCNTL_CKPT_START: number;
|
|
1123
|
+
/**
|
|
1124
|
+
* @constant 40
|
|
1125
|
+
*/
|
|
1126
|
+
SQLITE_FCNTL_EXTERNAL_READER: number;
|
|
1127
|
+
/**
|
|
1128
|
+
* @constant 41
|
|
1129
|
+
*/
|
|
1130
|
+
SQLITE_FCNTL_CKSM_FILE: number;
|
|
1131
|
+
/**
|
|
1132
|
+
* @constant 42
|
|
1133
|
+
*/
|
|
1134
|
+
SQLITE_FCNTL_RESET_CACHE: number;
|
|
1135
|
+
};
|
|
1162
1136
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1137
|
+
/**
|
|
1138
|
+
* The native module implementing the sqlite3 C bindings
|
|
1139
|
+
*
|
|
1140
|
+
* It is lazily-initialized, so this will return `undefined` until the first
|
|
1141
|
+
* call to new Database().
|
|
1142
|
+
*
|
|
1143
|
+
* The native module makes no gurantees about ABI stability, so it is left
|
|
1144
|
+
* untyped
|
|
1145
|
+
*
|
|
1146
|
+
* If you need to use it directly for some reason, please let us know because
|
|
1147
|
+
* that probably points to a deficiency in this API.
|
|
1148
|
+
*/
|
|
1149
|
+
export var native: any;
|
|
1176
1150
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
string,
|
|
1186
|
-
string | bigint | NodeJS.TypedArray | number | boolean | null
|
|
1187
|
-
>;
|
|
1151
|
+
export type SQLQueryBindings =
|
|
1152
|
+
| string
|
|
1153
|
+
| bigint
|
|
1154
|
+
| NodeJS.TypedArray
|
|
1155
|
+
| number
|
|
1156
|
+
| boolean
|
|
1157
|
+
| null
|
|
1158
|
+
| Record<string, string | bigint | NodeJS.TypedArray | number | boolean | null>;
|
|
1188
1159
|
|
|
1189
|
-
|
|
1160
|
+
export default Database;
|
|
1190
1161
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1162
|
+
/**
|
|
1163
|
+
* Errors from SQLite have a name `SQLiteError`.
|
|
1164
|
+
*
|
|
1165
|
+
*/
|
|
1166
|
+
export class SQLiteError extends Error {
|
|
1167
|
+
readonly name: "SQLiteError";
|
|
1197
1168
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1169
|
+
/**
|
|
1170
|
+
* The SQLite3 extended error code
|
|
1171
|
+
*
|
|
1172
|
+
* This corresponds to `sqlite3_extended_errcode`.
|
|
1173
|
+
*
|
|
1174
|
+
* @since v1.0.21
|
|
1175
|
+
*/
|
|
1176
|
+
errno: number;
|
|
1206
1177
|
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1178
|
+
/**
|
|
1179
|
+
* The name of the SQLite3 error code
|
|
1180
|
+
*
|
|
1181
|
+
* @example
|
|
1182
|
+
* "SQLITE_CONSTRAINT_UNIQUE"
|
|
1183
|
+
*
|
|
1184
|
+
* @since v1.0.21
|
|
1185
|
+
*/
|
|
1186
|
+
code?: string;
|
|
1216
1187
|
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1188
|
+
/**
|
|
1189
|
+
* The UTF-8 byte offset of the sqlite3 query that failed, if known
|
|
1190
|
+
*
|
|
1191
|
+
* This corresponds to `sqlite3_error_offset`.
|
|
1192
|
+
*
|
|
1193
|
+
* @since v1.0.21
|
|
1194
|
+
*/
|
|
1195
|
+
readonly byteOffset: number;
|
|
1196
|
+
}
|
|
1226
1197
|
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1198
|
+
/**
|
|
1199
|
+
* An object representing the changes made to the database since the last `run` or `exec` call.
|
|
1200
|
+
*
|
|
1201
|
+
* @since Bun v1.1.14
|
|
1202
|
+
*/
|
|
1203
|
+
export interface Changes {
|
|
1204
|
+
/**
|
|
1205
|
+
* The number of rows changed by the last `run` or `exec` call.
|
|
1206
|
+
*/
|
|
1207
|
+
changes: number;
|
|
1237
1208
|
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1209
|
+
/**
|
|
1210
|
+
* If `safeIntegers` is `true`, this is a `bigint`. Otherwise, it is a `number`.
|
|
1211
|
+
*/
|
|
1212
|
+
lastInsertRowid: number | bigint;
|
|
1213
|
+
}
|
|
1243
1214
|
}
|