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/sqlite.d.ts CHANGED
@@ -24,1220 +24,1191 @@
24
24
  * | `null` | `NULL` |
25
25
  */
26
26
  declare module "bun:sqlite" {
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;
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
- * 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;
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
- * 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
- );
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
- * 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;
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
- * 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[]>(
203
- sqlQuery: string,
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
- exec<ParamsType extends SQLQueryBindings[]>(
210
- sqlQuery: string,
211
- ...bindings: ParamsType[]
212
- ): Changes;
206
+ exec<ParamsType extends SQLQueryBindings[]>(sqlQuery: string, ...bindings: ParamsType[]): Changes;
213
207
 
214
- /**
215
- * Compile a SQL query and return a {@link Statement} object. This is the
216
- * same as {@link prepare} except that it caches the compiled query.
217
- *
218
- * This **does not execute** the query, but instead prepares it for later
219
- * execution and caches the compiled query if possible.
220
- *
221
- * @example
222
- * ```ts
223
- * // compile the query
224
- * const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
225
- * // run the query
226
- * stmt.all("baz");
227
- *
228
- * // run the query again
229
- * stmt.all();
230
- * ```
231
- *
232
- * @param sql The SQL query to compile
233
- *
234
- * @returns `Statment` instance
235
- *
236
- * Under the hood, this calls `sqlite3_prepare_v3`.
237
- */
238
- query<ReturnType, ParamsType extends SQLQueryBindings | SQLQueryBindings[]>(
239
- sqlQuery: string,
240
- ): // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
241
- Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
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
- * Compile a SQL query and return a {@link Statement} object.
245
- *
246
- * This does not cache the compiled query and does not execute the query.
247
- *
248
- * @example
249
- * ```ts
250
- * // compile the query
251
- * const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
252
- * // run the query
253
- * stmt.all("baz");
254
- * ```
255
- *
256
- * @param sql The SQL query to compile
257
- * @param params Optional bindings for the query
258
- *
259
- * @returns `Statment` instance
260
- *
261
- * Under the hood, this calls `sqlite3_prepare_v3`.
262
- */
263
- prepare<
264
- ReturnType,
265
- ParamsType extends SQLQueryBindings | SQLQueryBindings[],
266
- >(
267
- sqlQuery: string,
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
- * Is the database in a transaction?
274
- *
275
- * @returns `true` if the database is in a transaction, `false` otherwise
276
- *
277
- * @example
278
- * ```ts
279
- * db.run("CREATE TABLE foo (bar TEXT)");
280
- * db.run("INSERT INTO foo VALUES (?)", ["baz"]);
281
- * db.run("BEGIN");
282
- * db.run("INSERT INTO foo VALUES (?)", ["qux"]);
283
- * console.log(db.inTransaction());
284
- * ```
285
- */
286
- get inTransaction(): boolean;
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
- * Close the database connection.
290
- *
291
- * It is safe to call this method multiple times. If the database is already
292
- * closed, this is a no-op. Running queries after the database has been
293
- * closed will throw an error.
294
- *
295
- * @example
296
- * ```ts
297
- * db.close();
298
- * ```
299
- * This is called automatically when the database instance is garbage collected.
300
- *
301
- * Internally, this calls `sqlite3_close_v2`.
302
- */
303
- close(
304
- /**
305
- * If `true`, then the database will throw an error if it is in use
306
- * @default false
307
- *
308
- * When true, this calls `sqlite3_close` instead of `sqlite3_close_v2`.
309
- *
310
- * Learn more about this in the [sqlite3 documentation](https://www.sqlite.org/c3ref/close.html).
311
- *
312
- * Bun will automatically call close by default when the database instance is garbage collected.
313
- * In The future, Bun may default `throwOnError` to be true but for backwards compatibility, it is false by default.
314
- */
315
- throwOnError?: boolean,
316
- ): void;
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
- * The filename passed when `new Database()` was called
320
- * @example
321
- * ```ts
322
- * const db = new Database("mydb.sqlite");
323
- * console.log(db.filename);
324
- * // => "mydb.sqlite"
325
- * ```
326
- */
327
- readonly filename: string;
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
- * The underlying `sqlite3` database handle
331
- *
332
- * In native code, this is not a file descriptor, but an index into an array of database handles
333
- */
334
- readonly handle: number;
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
- * Load a SQLite3 extension
338
- *
339
- * macOS requires a custom SQLite3 library to be linked because the Apple build of SQLite for macOS disables loading extensions. See {@link Database.setCustomSQLite}
340
- *
341
- * Bun chooses the Apple build of SQLite on macOS because it brings a ~50% performance improvement.
342
- *
343
- * @param extension name/path of the extension to load
344
- * @param entryPoint optional entry point of the extension
345
- */
346
- loadExtension(extension: string, entryPoint?: string): void;
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
- * Change the dynamic library path to SQLite
350
- *
351
- * @note macOS-only
352
- *
353
- * This only works before SQLite is loaded, so
354
- * that's before you call `new Database()`.
355
- *
356
- * It can only be run once because this will load
357
- * the SQLite library into the process.
358
- *
359
- * @param path The path to the SQLite library
360
- */
361
- static setCustomSQLite(path: string): boolean;
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
- [Symbol.dispose](): void;
354
+ [Symbol.dispose](): void;
364
355
 
365
- /**
366
- * Creates a function that always runs inside a transaction. When the
367
- * function is invoked, it will begin a new transaction. When the function
368
- * returns, the transaction will be committed. If an exception is thrown,
369
- * the transaction will be rolled back (and the exception will propagate as
370
- * usual).
371
- *
372
- * @param insideTransaction The callback which runs inside a transaction
373
- *
374
- * @example
375
- * ```ts
376
- * // setup
377
- * import { Database } from "bun:sqlite";
378
- * const db = Database.open(":memory:");
379
- * db.exec(
380
- * "CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)"
381
- * );
382
- *
383
- * const insert = db.prepare("INSERT INTO cats (name, age) VALUES ($name, $age)");
384
- * const insertMany = db.transaction((cats) => {
385
- * for (const cat of cats) insert.run(cat);
386
- * });
387
- *
388
- * insertMany([
389
- * { $name: "Joey", $age: 2 },
390
- * { $name: "Sally", $age: 4 },
391
- * { $name: "Junior", $age: 1 },
392
- * ]);
393
- * ```
394
- */
395
- transaction(insideTransaction: (...args: any) => void): CallableFunction & {
396
- /**
397
- * uses "BEGIN DEFERRED"
398
- */
399
- deferred: (...args: any) => void;
400
- /**
401
- * uses "BEGIN IMMEDIATE"
402
- */
403
- immediate: (...args: any) => void;
404
- /**
405
- * uses "BEGIN EXCLUSIVE"
406
- */
407
- exclusive: (...args: any) => void;
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
- * Save the database to an in-memory {@link Buffer} object.
412
- *
413
- * Internally, this calls `sqlite3_serialize`.
414
- *
415
- * @param name Name to save the database as @default "main"
416
- * @returns Buffer containing the serialized database
417
- */
418
- serialize(name?: string): Buffer;
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
- * Load a serialized SQLite3 database
422
- *
423
- * Internally, this calls `sqlite3_deserialize`.
424
- *
425
- * @param serialized Data to load
426
- * @returns `Database` instance
427
- *
428
- * @example
429
- * ```ts
430
- * test("supports serialize/deserialize", () => {
431
- * const db = Database.open(":memory:");
432
- * db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");
433
- * db.exec('INSERT INTO test (name) VALUES ("Hello")');
434
- * db.exec('INSERT INTO test (name) VALUES ("World")');
435
- *
436
- * const input = db.serialize();
437
- * const db2 = new Database(input);
438
- *
439
- * const stmt = db2.prepare("SELECT * FROM test");
440
- * expect(JSON.stringify(stmt.get())).toBe(
441
- * JSON.stringify({
442
- * id: 1,
443
- * name: "Hello",
444
- * }),
445
- * );
446
- *
447
- * expect(JSON.stringify(stmt.all())).toBe(
448
- * JSON.stringify([
449
- * {
450
- * id: 1,
451
- * name: "Hello",
452
- * },
453
- * {
454
- * id: 2,
455
- * name: "World",
456
- * },
457
- * ]),
458
- * );
459
- * db2.exec("insert into test (name) values ('foo')");
460
- * expect(JSON.stringify(stmt.all())).toBe(
461
- * JSON.stringify([
462
- * {
463
- * id: 1,
464
- * name: "Hello",
465
- * },
466
- * {
467
- * id: 2,
468
- * name: "World",
469
- * },
470
- * {
471
- * id: 3,
472
- * name: "foo",
473
- * },
474
- * ]),
475
- * );
476
- *
477
- * const db3 = Database.deserialize(input, true);
478
- * try {
479
- * db3.exec("insert into test (name) values ('foo')");
480
- * throw new Error("Expected error");
481
- * } catch (e) {
482
- * expect(e.message).toBe("attempt to write a readonly database");
483
- * }
484
- * });
485
- * ```
486
- */
487
- static deserialize(
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
- * Load a serialized SQLite3 database. This version enables you to specify
494
- * additional options such as `strict` to put the database into strict mode.
495
- *
496
- * Internally, this calls `sqlite3_deserialize`.
497
- *
498
- * @param serialized Data to load
499
- * @returns `Database` instance
500
- *
501
- * @example
502
- * ```ts
503
- * test("supports serialize/deserialize", () => {
504
- * const db = Database.open(":memory:");
505
- * db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");
506
- * db.exec('INSERT INTO test (name) VALUES ("Hello")');
507
- * db.exec('INSERT INTO test (name) VALUES ("World")');
508
- *
509
- * const input = db.serialize();
510
- * const db2 = Database.deserialize(input, { strict: true });
511
- *
512
- * const stmt = db2.prepare("SELECT * FROM test");
513
- * expect(JSON.stringify(stmt.get())).toBe(
514
- * JSON.stringify({
515
- * id: 1,
516
- * name: "Hello",
517
- * }),
518
- * );
519
- *
520
- * expect(JSON.stringify(stmt.all())).toBe(
521
- * JSON.stringify([
522
- * {
523
- * id: 1,
524
- * name: "Hello",
525
- * },
526
- * {
527
- * id: 2,
528
- * name: "World",
529
- * },
530
- * ]),
531
- * );
532
- * db2.exec("insert into test (name) values ($foo)", { foo: "baz" });
533
- * expect(JSON.stringify(stmt.all())).toBe(
534
- * JSON.stringify([
535
- * {
536
- * id: 1,
537
- * name: "Hello",
538
- * },
539
- * {
540
- * id: 2,
541
- * name: "World",
542
- * },
543
- * {
544
- * id: 3,
545
- * name: "baz",
546
- * },
547
- * ]),
548
- * );
549
- *
550
- * const db3 = Database.deserialize(input, { readonly: true, strict: true });
551
- * try {
552
- * db3.exec("insert into test (name) values ($foo)", { foo: "baz" });
553
- * throw new Error("Expected error");
554
- * } catch (e) {
555
- * expect(e.message).toBe("attempt to write a readonly database");
556
- * }
557
- * });
558
- * ```
559
- */
560
- static deserialize(
561
- serialized: NodeJS.TypedArray | ArrayBufferLike,
562
- options?: {
563
- readonly?: boolean;
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
- * See `sqlite3_file_control` for more information.
571
- * @link https://www.sqlite.org/c3ref/file_control.html
572
- */
573
- fileControl(op: number, arg?: ArrayBufferView | number): number;
574
- /**
575
- * See `sqlite3_file_control` for more information.
576
- * @link https://www.sqlite.org/c3ref/file_control.html
577
- */
578
- fileControl(
579
- zDbName: string,
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
- * A prepared statement.
587
- *
588
- * This is returned by {@link Database.prepare} and {@link Database.query}.
589
- *
590
- * @example
591
- * ```ts
592
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
593
- * stmt.all("baz");
594
- * // => [{bar: "baz"}]
595
- * ```
596
- *
597
- * @example
598
- * ```ts
599
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
600
- * stmt.get("baz");
601
- * // => {bar: "baz"}
602
- * ```
603
- *
604
- * @example
605
- * ```ts
606
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
607
- * stmt.run("baz");
608
- * // => undefined
609
- * ```
610
- */
611
- export class Statement<
612
- ReturnType = unknown,
613
- ParamsType extends SQLQueryBindings[] = any[],
614
- > implements Disposable
615
- {
616
- /**
617
- * Creates a new prepared statement from native code.
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
- * Execute the prepared statement and return all results as objects.
625
- *
626
- * @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.
627
- *
628
- * @example
629
- * ```ts
630
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
631
- *
632
- * stmt.all("baz");
633
- * // => [{bar: "baz"}]
634
- *
635
- * stmt.all();
636
- * // => []
637
- *
638
- * stmt.all("foo");
639
- * // => [{bar: "foo"}]
640
- * ```
641
- */
642
- all(...params: ParamsType): ReturnType[];
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
- * Execute the prepared statement and return **the first** result.
646
- *
647
- * If no result is returned, this returns `null`.
648
- *
649
- * @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.
650
- *
651
- * @example
652
- * ```ts
653
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
654
- *
655
- * stmt.get("baz");
656
- * // => {bar: "baz"}
657
- *
658
- * stmt.get();
659
- * // => null
660
- *
661
- * stmt.get("foo");
662
- * // => {bar: "foo"}
663
- * ```
664
- *
665
- * The following types can be used when binding parameters:
666
- *
667
- * | JavaScript type | SQLite type |
668
- * | -------------- | ----------- |
669
- * | `string` | `TEXT` |
670
- * | `number` | `INTEGER` or `DECIMAL` |
671
- * | `boolean` | `INTEGER` (1 or 0) |
672
- * | `Uint8Array` | `BLOB` |
673
- * | `Buffer` | `BLOB` |
674
- * | `bigint` | `INTEGER` |
675
- * | `null` | `NULL` |
676
- */
677
- get(...params: ParamsType): ReturnType | null;
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
- * Execute the prepared statement and return an
681
- *
682
- * @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.
683
- *
684
- */
685
- iterate(...params: ParamsType): IterableIterator<ReturnType>;
686
- [Symbol.iterator](): IterableIterator<ReturnType>;
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
- * Execute the prepared statement. This returns `undefined`.
690
- *
691
- * @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.
692
- *
693
- * @example
694
- * ```ts
695
- * const stmt = db.prepare("UPDATE foo SET bar = ?");
696
- * stmt.run("baz");
697
- * // => undefined
698
- *
699
- * stmt.run();
700
- * // => undefined
701
- *
702
- * stmt.run("foo");
703
- * // => undefined
704
- * ```
705
- *
706
- * The following types can be used when binding parameters:
707
- *
708
- * | JavaScript type | SQLite type |
709
- * | -------------- | ----------- |
710
- * | `string` | `TEXT` |
711
- * | `number` | `INTEGER` or `DECIMAL` |
712
- * | `boolean` | `INTEGER` (1 or 0) |
713
- * | `Uint8Array` | `BLOB` |
714
- * | `Buffer` | `BLOB` |
715
- * | `bigint` | `INTEGER` |
716
- * | `null` | `NULL` |
717
- */
718
- run(...params: ParamsType): Changes;
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
- * Execute the prepared statement and return the results as an array of arrays.
722
- *
723
- * In Bun v0.6.7 and earlier, this method returned `null` if there were no
724
- * results instead of `[]`. This was changed in v0.6.8 to align
725
- * more with what people expect.
726
- *
727
- * @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.
728
- *
729
- * @example
730
- * ```ts
731
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
732
- *
733
- * stmt.values("baz");
734
- * // => [['baz']]
735
- *
736
- * stmt.values();
737
- * // => [['baz']]
738
- *
739
- * stmt.values("foo");
740
- * // => [['foo']]
741
- *
742
- * stmt.values("not-found");
743
- * // => []
744
- * ```
745
- *
746
- * The following types can be used when binding parameters:
747
- *
748
- * | JavaScript type | SQLite type |
749
- * | ---------------|-------------|
750
- * | `string` | `TEXT` |
751
- * | `number` | `INTEGER` or `DECIMAL` |
752
- * | `boolean` | `INTEGER` (1 or 0) |
753
- * | `Uint8Array` | `BLOB` |
754
- * | `Buffer` | `BLOB` |
755
- * | `bigint` | `INTEGER` |
756
- * | `null` | `NULL` |
757
- */
758
- values(
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
- * The names of the columns returned by the prepared statement.
764
- * @example
765
- * ```ts
766
- * const stmt = db.prepare("SELECT bar FROM foo WHERE bar = ?");
767
- *
768
- * console.log(stmt.columnNames);
769
- * // => ["bar"]
770
- * ```
771
- */
772
- readonly columnNames: string[];
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
- * The number of parameters expected in the prepared statement.
776
- * @example
777
- * ```ts
778
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
779
- * console.log(stmt.paramsCount);
780
- * // => 1
781
- * ```
782
- * @example
783
- * ```ts
784
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?");
785
- * console.log(stmt.paramsCount);
786
- * // => 2
787
- * ```
788
- */
789
- readonly paramsCount: number;
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
- * Finalize the prepared statement, freeing the resources used by the
793
- * statement and preventing it from being executed again.
794
- *
795
- * This is called automatically when the prepared statement is garbage collected.
796
- *
797
- * It is safe to call this multiple times. Calling this on a finalized
798
- * statement has no effect.
799
- *
800
- * Internally, this calls `sqlite3_finalize`.
801
- */
802
- finalize(): void;
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
- * Calls {@link finalize} if it wasn't already called.
806
- */
807
- [Symbol.dispose](): void;
778
+ /**
779
+ * Calls {@link finalize} if it wasn't already called.
780
+ */
781
+ [Symbol.dispose](): void;
808
782
 
809
- /**
810
- * Return the expanded SQL string for the prepared statement.
811
- *
812
- * Internally, this calls `sqlite3_expanded_sql()` on the underlying `sqlite3_stmt`.
813
- *
814
- * @example
815
- * ```ts
816
- * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?", "baz");
817
- * console.log(stmt.toString());
818
- * // => "SELECT * FROM foo WHERE bar = 'baz'"
819
- * console.log(stmt);
820
- * // => "SELECT * FROM foo WHERE bar = 'baz'"
821
- * ```
822
- */
823
- toString(): string;
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
- * Make {@link get} and {@link all} return an instance of the provided
828
- * `Class` instead of the default `Object`.
829
- *
830
- * @param Class A class to use
831
- * @returns The same statement instance, modified to return an instance of `Class`
832
- *
833
- * This lets you attach methods, getters, and setters to the returned
834
- * objects.
835
- *
836
- * For performance reasons, constructors for classes are not called, which means
837
- * initializers will not be called and private fields will not be
838
- * accessible.
839
- *
840
- * @example
841
- *
842
- * ## Custom class
843
- * ```ts
844
- * class User {
845
- * rawBirthdate: string;
846
- * get birthdate() {
847
- * return new Date(this.rawBirthdate);
848
- * }
849
- * }
850
- *
851
- * const db = new Database(":memory:");
852
- * db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, rawBirthdate TEXT)");
853
- * db.run("INSERT INTO users (rawBirthdate) VALUES ('1995-12-19')");
854
- * const query = db.query("SELECT * FROM users");
855
- * query.as(User);
856
- * const user = query.get();
857
- * console.log(user.birthdate);
858
- * // => Date(1995, 12, 19)
859
- * ```
860
- */
861
- as<T = unknown>(Class: new (...args: any[]) => T): Statement<T, ParamsType>;
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
- * Native object representing the underlying `sqlite3_stmt`
865
- *
866
- * This is left untyped because the ABI of the native bindings may change at any time.
867
- */
868
- readonly native: any;
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
- * Constants from `sqlite3.h`
873
- *
874
- * This list isn't exhaustive, but some of the ones which are relevant
875
- */
876
- export const constants: {
877
- /**
878
- * Open the database as read-only (no write operations, no create).
879
- * @constant 0x00000001
880
- */
881
- SQLITE_OPEN_READONLY: number;
882
- /**
883
- * Open the database for reading and writing
884
- * @constant 0x00000002
885
- */
886
- SQLITE_OPEN_READWRITE: number;
887
- /**
888
- * Allow creating a new database
889
- * @constant 0x00000004
890
- */
891
- SQLITE_OPEN_CREATE: number;
892
- /**
893
- * @constant 0x00000008
894
- */
895
- SQLITE_OPEN_DELETEONCLOSE: number;
896
- /**
897
- * @constant 0x00000010
898
- */
899
- SQLITE_OPEN_EXCLUSIVE: number;
900
- /**
901
- * @constant 0x00000020
902
- */
903
- SQLITE_OPEN_AUTOPROXY: number;
904
- /**
905
- * @constant 0x00000040
906
- */
907
- SQLITE_OPEN_URI: number;
908
- /**
909
- * @constant 0x00000080
910
- */
911
- SQLITE_OPEN_MEMORY: number;
912
- /**
913
- * @constant 0x00000100
914
- */
915
- SQLITE_OPEN_MAIN_DB: number;
916
- /**
917
- * @constant 0x00000200
918
- */
919
- SQLITE_OPEN_TEMP_DB: number;
920
- /**
921
- * @constant 0x00000400
922
- */
923
- SQLITE_OPEN_TRANSIENT_DB: number;
924
- /**
925
- * @constant 0x00000800
926
- */
927
- SQLITE_OPEN_MAIN_JOURNAL: number;
928
- /**
929
- * @constant 0x00001000
930
- */
931
- SQLITE_OPEN_TEMP_JOURNAL: number;
932
- /**
933
- * @constant 0x00002000
934
- */
935
- SQLITE_OPEN_SUBJOURNAL: number;
936
- /**
937
- * @constant 0x00004000
938
- */
939
- SQLITE_OPEN_SUPER_JOURNAL: number;
940
- /**
941
- * @constant 0x00008000
942
- */
943
- SQLITE_OPEN_NOMUTEX: number;
944
- /**
945
- * @constant 0x00010000
946
- */
947
- SQLITE_OPEN_FULLMUTEX: number;
948
- /**
949
- * @constant 0x00020000
950
- */
951
- SQLITE_OPEN_SHAREDCACHE: number;
952
- /**
953
- * @constant 0x00040000
954
- */
955
- SQLITE_OPEN_PRIVATECACHE: number;
956
- /**
957
- * @constant 0x00080000
958
- */
959
- SQLITE_OPEN_WAL: number;
960
- /**
961
- * @constant 0x01000000
962
- */
963
- SQLITE_OPEN_NOFOLLOW: number;
964
- /**
965
- * @constant 0x02000000
966
- */
967
- SQLITE_OPEN_EXRESCODE: number;
968
- /**
969
- * @constant 0x01
970
- */
971
- SQLITE_PREPARE_PERSISTENT: number;
972
- /**
973
- * @constant 0x02
974
- */
975
- SQLITE_PREPARE_NORMALIZE: number;
976
- /**
977
- * @constant 0x04
978
- */
979
- SQLITE_PREPARE_NO_VTAB: number;
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
- * @constant 1
983
- */
984
- SQLITE_FCNTL_LOCKSTATE: number;
985
- /**
986
- * @constant 2
987
- */
988
- SQLITE_FCNTL_GET_LOCKPROXYFILE: number;
989
- /**
990
- * @constant 3
991
- */
992
- SQLITE_FCNTL_SET_LOCKPROXYFILE: number;
993
- /**
994
- * @constant 4
995
- */
996
- SQLITE_FCNTL_LAST_ERRNO: number;
997
- /**
998
- * @constant 5
999
- */
1000
- SQLITE_FCNTL_SIZE_HINT: number;
1001
- /**
1002
- * @constant 6
1003
- */
1004
- SQLITE_FCNTL_CHUNK_SIZE: number;
1005
- /**
1006
- * @constant 7
1007
- */
1008
- SQLITE_FCNTL_FILE_POINTER: number;
1009
- /**
1010
- * @constant 8
1011
- */
1012
- SQLITE_FCNTL_SYNC_OMITTED: number;
1013
- /**
1014
- * @constant 9
1015
- */
1016
- SQLITE_FCNTL_WIN32_AV_RETRY: number;
1017
- /**
1018
- * @constant 10
1019
- *
1020
- * Control whether or not the WAL is persisted
1021
- * Some versions of macOS configure WAL to be persistent by default.
1022
- *
1023
- * You can change this with code like the below:
1024
- * ```ts
1025
- * import { Database } from "bun:sqlite";
1026
- *
1027
- * const db = Database.open("mydb.sqlite");
1028
- * db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0);
1029
- * // enable WAL
1030
- * db.exec("PRAGMA journal_mode = WAL");
1031
- * // .. do some work
1032
- * db.close();
1033
- * ```
1034
- *
1035
- */
1036
- SQLITE_FCNTL_PERSIST_WAL: number;
1037
- /**
1038
- * @constant 11
1039
- */
1040
- SQLITE_FCNTL_OVERWRITE: number;
1041
- /**
1042
- * @constant 12
1043
- */
1044
- SQLITE_FCNTL_VFSNAME: number;
1045
- /**
1046
- * @constant 13
1047
- */
1048
- SQLITE_FCNTL_POWERSAFE_OVERWRITE: number;
1049
- /**
1050
- * @constant 14
1051
- */
1052
- SQLITE_FCNTL_PRAGMA: number;
1053
- /**
1054
- * @constant 15
1055
- */
1056
- SQLITE_FCNTL_BUSYHANDLER: number;
1057
- /**
1058
- * @constant 16
1059
- */
1060
- SQLITE_FCNTL_TEMPFILENAME: number;
1061
- /**
1062
- * @constant 18
1063
- */
1064
- SQLITE_FCNTL_MMAP_SIZE: number;
1065
- /**
1066
- * @constant 19
1067
- */
1068
- SQLITE_FCNTL_TRACE: number;
1069
- /**
1070
- * @constant 20
1071
- */
1072
- SQLITE_FCNTL_HAS_MOVED: number;
1073
- /**
1074
- * @constant 21
1075
- */
1076
- SQLITE_FCNTL_SYNC: number;
1077
- /**
1078
- * @constant 22
1079
- */
1080
- SQLITE_FCNTL_COMMIT_PHASETWO: number;
1081
- /**
1082
- * @constant 23
1083
- */
1084
- SQLITE_FCNTL_WIN32_SET_HANDLE: number;
1085
- /**
1086
- * @constant 24
1087
- */
1088
- SQLITE_FCNTL_WAL_BLOCK: number;
1089
- /**
1090
- * @constant 25
1091
- */
1092
- SQLITE_FCNTL_ZIPVFS: number;
1093
- /**
1094
- * @constant 26
1095
- */
1096
- SQLITE_FCNTL_RBU: number;
1097
- /**
1098
- * @constant 27
1099
- */
1100
- SQLITE_FCNTL_VFS_POINTER: number;
1101
- /**
1102
- * @constant 28
1103
- */
1104
- SQLITE_FCNTL_JOURNAL_POINTER: number;
1105
- /**
1106
- * @constant 29
1107
- */
1108
- SQLITE_FCNTL_WIN32_GET_HANDLE: number;
1109
- /**
1110
- * @constant 30
1111
- */
1112
- SQLITE_FCNTL_PDB: number;
1113
- /**
1114
- * @constant 31
1115
- */
1116
- SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: number;
1117
- /**
1118
- * @constant 32
1119
- */
1120
- SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: number;
1121
- /**
1122
- * @constant 33
1123
- */
1124
- SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: number;
1125
- /**
1126
- * @constant 34
1127
- */
1128
- SQLITE_FCNTL_LOCK_TIMEOUT: number;
1129
- /**
1130
- * @constant 35
1131
- */
1132
- SQLITE_FCNTL_DATA_VERSION: number;
1133
- /**
1134
- * @constant 36
1135
- */
1136
- SQLITE_FCNTL_SIZE_LIMIT: number;
1137
- /**
1138
- * @constant 37
1139
- */
1140
- SQLITE_FCNTL_CKPT_DONE: number;
1141
- /**
1142
- * @constant 38
1143
- */
1144
- SQLITE_FCNTL_RESERVE_BYTES: number;
1145
- /**
1146
- * @constant 39
1147
- */
1148
- SQLITE_FCNTL_CKPT_START: number;
1149
- /**
1150
- * @constant 40
1151
- */
1152
- SQLITE_FCNTL_EXTERNAL_READER: number;
1153
- /**
1154
- * @constant 41
1155
- */
1156
- SQLITE_FCNTL_CKSM_FILE: number;
1157
- /**
1158
- * @constant 42
1159
- */
1160
- SQLITE_FCNTL_RESET_CACHE: number;
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
- * The native module implementing the sqlite3 C bindings
1165
- *
1166
- * It is lazily-initialized, so this will return `undefined` until the first
1167
- * call to new Database().
1168
- *
1169
- * The native module makes no gurantees about ABI stability, so it is left
1170
- * untyped
1171
- *
1172
- * If you need to use it directly for some reason, please let us know because
1173
- * that probably points to a deficiency in this API.
1174
- */
1175
- export var native: any;
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
- export type SQLQueryBindings =
1178
- | string
1179
- | bigint
1180
- | NodeJS.TypedArray
1181
- | number
1182
- | boolean
1183
- | null
1184
- | Record<
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
- export default Database;
1160
+ export default Database;
1190
1161
 
1191
- /**
1192
- * Errors from SQLite have a name `SQLiteError`.
1193
- *
1194
- */
1195
- export class SQLiteError extends Error {
1196
- readonly name: "SQLiteError";
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
- * The SQLite3 extended error code
1200
- *
1201
- * This corresponds to `sqlite3_extended_errcode`.
1202
- *
1203
- * @since v1.0.21
1204
- */
1205
- errno: number;
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
- * The name of the SQLite3 error code
1209
- *
1210
- * @example
1211
- * "SQLITE_CONSTRAINT_UNIQUE"
1212
- *
1213
- * @since v1.0.21
1214
- */
1215
- code?: string;
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
- * The UTF-8 byte offset of the sqlite3 query that failed, if known
1219
- *
1220
- * This corresponds to `sqlite3_error_offset`.
1221
- *
1222
- * @since v1.0.21
1223
- */
1224
- readonly byteOffset: number;
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
- * An object representing the changes made to the database since the last `run` or `exec` call.
1229
- *
1230
- * @since Bun v1.1.14
1231
- */
1232
- export interface Changes {
1233
- /**
1234
- * The number of rows changed by the last `run` or `exec` call.
1235
- */
1236
- changes: number;
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
- * If `safeIntegers` is `true`, this is a `bigint`. Otherwise, it is a `number`.
1240
- */
1241
- lastInsertRowid: number | bigint;
1242
- }
1209
+ /**
1210
+ * If `safeIntegers` is `true`, this is a `bigint`. Otherwise, it is a `number`.
1211
+ */
1212
+ lastInsertRowid: number | bigint;
1213
+ }
1243
1214
  }