bun-types 1.0.25 → 1.0.26

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 ADDED
@@ -0,0 +1,831 @@
1
+ /**
2
+ * Fast SQLite3 driver for Bun.js
3
+ * @since v0.0.83
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { Database } from 'bun:sqlite';
8
+ *
9
+ * var db = new Database('app.db');
10
+ * db.query('SELECT * FROM users WHERE name = ?').all('John');
11
+ * // => [{ id: 1, name: 'John' }]
12
+ * ```
13
+ *
14
+ * The following types can be used when binding parameters:
15
+ *
16
+ * | JavaScript type | SQLite type |
17
+ * | -------------- | ----------- |
18
+ * | `string` | `TEXT` |
19
+ * | `number` | `INTEGER` or `DECIMAL` |
20
+ * | `boolean` | `INTEGER` (1 or 0) |
21
+ * | `Uint8Array` | `BLOB` |
22
+ * | `Buffer` | `BLOB` |
23
+ * | `bigint` | `INTEGER` |
24
+ * | `null` | `NULL` |
25
+ */
26
+ declare module "bun:sqlite" {
27
+ export class Database {
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
+ },
86
+ );
87
+
88
+ /**
89
+ * This is an alias of `new Database()`
90
+ *
91
+ * See {@link Database}
92
+ */
93
+ static open(
94
+ filename: string,
95
+ options?:
96
+ | number
97
+ | {
98
+ /**
99
+ * Open the database as read-only (no write operations, no create).
100
+ *
101
+ * Equivalent to {@link constants.SQLITE_OPEN_READONLY}
102
+ */
103
+ readonly?: boolean;
104
+ /**
105
+ * Allow creating a new database
106
+ *
107
+ * Equivalent to {@link constants.SQLITE_OPEN_CREATE}
108
+ */
109
+ create?: boolean;
110
+ /**
111
+ * Open the database as read-write
112
+ *
113
+ * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
114
+ */
115
+ readwrite?: boolean;
116
+ },
117
+ ): Database;
118
+
119
+ /**
120
+ * Execute a SQL query **without returning any results**.
121
+ *
122
+ * This does not cache the query, so if you want to run a query multiple times, you should use {@link prepare} instead.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * db.run("CREATE TABLE foo (bar TEXT)");
127
+ * db.run("INSERT INTO foo VALUES (?)", "baz");
128
+ * ```
129
+ *
130
+ * Useful for queries like:
131
+ * - `CREATE TABLE`
132
+ * - `INSERT INTO`
133
+ * - `UPDATE`
134
+ * - `DELETE FROM`
135
+ * - `DROP TABLE`
136
+ * - `PRAGMA`
137
+ * - `ATTACH DATABASE`
138
+ * - `DETACH DATABASE`
139
+ * - `REINDEX`
140
+ * - `VACUUM`
141
+ * - `EXPLAIN ANALYZE`
142
+ * - `CREATE INDEX`
143
+ * - `CREATE TRIGGER`
144
+ * - `CREATE VIEW`
145
+ * - `CREATE VIRTUAL TABLE`
146
+ * - `CREATE TEMPORARY TABLE`
147
+ *
148
+ * @param sql The SQL query to run
149
+ *
150
+ * @param bindings Optional bindings for the query
151
+ *
152
+ * @returns `Database` instance
153
+ *
154
+ * Under the hood, this calls `sqlite3_prepare_v3` followed by `sqlite3_step` and `sqlite3_finalize`.
155
+ *
156
+ * * The following types can be used when binding parameters:
157
+ *
158
+ * | JavaScript type | SQLite type |
159
+ * | -------------- | ----------- |
160
+ * | `string` | `TEXT` |
161
+ * | `number` | `INTEGER` or `DECIMAL` |
162
+ * | `boolean` | `INTEGER` (1 or 0) |
163
+ * | `Uint8Array` | `BLOB` |
164
+ * | `Buffer` | `BLOB` |
165
+ * | `bigint` | `INTEGER` |
166
+ * | `null` | `NULL` |
167
+ */
168
+ run<ParamsType extends SQLQueryBindings[]>(sqlQuery: string, ...bindings: ParamsType[]): void;
169
+ /**
170
+ This is an alias of {@link Database.prototype.run}
171
+ */
172
+ exec<ParamsType extends SQLQueryBindings[]>(sqlQuery: string, ...bindings: ParamsType[]): void;
173
+
174
+ /**
175
+ * Compile a SQL query and return a {@link Statement} object. This is the
176
+ * same as {@link prepare} except that it caches the compiled query.
177
+ *
178
+ * This **does not execute** the query, but instead prepares it for later
179
+ * execution and caches the compiled query if possible.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * // compile the query
184
+ * const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
185
+ * // run the query
186
+ * stmt.all("baz");
187
+ *
188
+ * // run the query again
189
+ * stmt.all();
190
+ * ```
191
+ *
192
+ * @param sql The SQL query to compile
193
+ *
194
+ * @returns `Statment` instance
195
+ *
196
+ * Under the hood, this calls `sqlite3_prepare_v3`.
197
+ */
198
+ query<ReturnType, ParamsType extends SQLQueryBindings | SQLQueryBindings[]>(
199
+ sqlQuery: string,
200
+ ): // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
201
+ Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
202
+
203
+ /**
204
+ * Compile a SQL query and return a {@link Statement} object.
205
+ *
206
+ * This does not cache the compiled query and does not execute the query.
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * // compile the query
211
+ * const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
212
+ * // run the query
213
+ * stmt.all("baz");
214
+ * ```
215
+ *
216
+ * @param sql The SQL query to compile
217
+ * @param params Optional bindings for the query
218
+ *
219
+ * @returns `Statment` instance
220
+ *
221
+ * Under the hood, this calls `sqlite3_prepare_v3`.
222
+ */
223
+ prepare<ReturnType, ParamsType extends SQLQueryBindings | SQLQueryBindings[]>(
224
+ sqlQuery: string,
225
+ params?: ParamsType,
226
+ ): // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
227
+ Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
228
+
229
+ /**
230
+ * Is the database in a transaction?
231
+ *
232
+ * @returns `true` if the database is in a transaction, `false` otherwise
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * db.run("CREATE TABLE foo (bar TEXT)");
237
+ * db.run("INSERT INTO foo VALUES (?)", "baz");
238
+ * db.run("BEGIN");
239
+ * db.run("INSERT INTO foo VALUES (?)", "qux");
240
+ * console.log(db.inTransaction());
241
+ * ```
242
+ */
243
+ get inTransaction(): boolean;
244
+
245
+ /**
246
+ * Close the database connection.
247
+ *
248
+ * It is safe to call this method multiple times. If the database is already
249
+ * closed, this is a no-op. Running queries after the database has been
250
+ * closed will throw an error.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * db.close();
255
+ * ```
256
+ * This is called automatically when the database instance is garbage collected.
257
+ *
258
+ * Internally, this calls `sqlite3_close_v2`.
259
+ */
260
+ close(): void;
261
+
262
+ /**
263
+ * The filename passed when `new Database()` was called
264
+ * @example
265
+ * ```ts
266
+ * const db = new Database("mydb.sqlite");
267
+ * console.log(db.filename);
268
+ * // => "mydb.sqlite"
269
+ * ```
270
+ */
271
+ readonly filename: string;
272
+
273
+ /**
274
+ * The underlying `sqlite3` database handle
275
+ *
276
+ * In native code, this is not a file descriptor, but an index into an array of database handles
277
+ */
278
+ readonly handle: number;
279
+
280
+ /**
281
+ * Load a SQLite3 extension
282
+ *
283
+ * macOS requires a custom SQLite3 library to be linked because the Apple build of SQLite for macOS disables loading extensions. See {@link Database.setCustomSQLite}
284
+ *
285
+ * Bun chooses the Apple build of SQLite on macOS because it brings a ~50% performance improvement.
286
+ *
287
+ * @param extension name/path of the extension to load
288
+ * @param entryPoint optional entry point of the extension
289
+ */
290
+ loadExtension(extension: string, entryPoint?: string): void;
291
+
292
+ /**
293
+ * Change the dynamic library path to SQLite
294
+ *
295
+ * @note macOS-only
296
+ *
297
+ * This only works before SQLite is loaded, so
298
+ * that's before you call `new Database()`.
299
+ *
300
+ * It can only be run once because this will load
301
+ * the SQLite library into the process.
302
+ *
303
+ * @param path The path to the SQLite library
304
+ */
305
+ static setCustomSQLite(path: string): boolean;
306
+
307
+ /**
308
+ * Creates a function that always runs inside a transaction. When the
309
+ * function is invoked, it will begin a new transaction. When the function
310
+ * returns, the transaction will be committed. If an exception is thrown,
311
+ * the transaction will be rolled back (and the exception will propagate as
312
+ * usual).
313
+ *
314
+ * @param insideTransaction The callback which runs inside a transaction
315
+ *
316
+ * @example
317
+ * ```ts
318
+ * // setup
319
+ * import { Database } from "bun:sqlite";
320
+ * const db = Database.open(":memory:");
321
+ * db.exec(
322
+ * "CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)"
323
+ * );
324
+ *
325
+ * const insert = db.prepare("INSERT INTO cats (name, age) VALUES ($name, $age)");
326
+ * const insertMany = db.transaction((cats) => {
327
+ * for (const cat of cats) insert.run(cat);
328
+ * });
329
+ *
330
+ * insertMany([
331
+ * { $name: "Joey", $age: 2 },
332
+ * { $name: "Sally", $age: 4 },
333
+ * { $name: "Junior", $age: 1 },
334
+ * ]);
335
+ * ```
336
+ */
337
+ transaction(insideTransaction: (...args: any) => void): CallableFunction & {
338
+ /**
339
+ * uses "BEGIN DEFERRED"
340
+ */
341
+ deferred: (...args: any) => void;
342
+ /**
343
+ * uses "BEGIN IMMEDIATE"
344
+ */
345
+ immediate: (...args: any) => void;
346
+ /**
347
+ * uses "BEGIN EXCLUSIVE"
348
+ */
349
+ exclusive: (...args: any) => void;
350
+ };
351
+
352
+ /**
353
+ * Save the database to an in-memory {@link Buffer} object.
354
+ *
355
+ * Internally, this calls `sqlite3_serialize`.
356
+ *
357
+ * @param name Name to save the database as @default "main"
358
+ * @returns Buffer containing the serialized database
359
+ */
360
+ serialize(name?: string): Buffer;
361
+
362
+ /**
363
+ * Load a serialized SQLite3 database
364
+ *
365
+ * Internally, this calls `sqlite3_deserialize`.
366
+ *
367
+ * @param serialized Data to load
368
+ * @returns `Database` instance
369
+ *
370
+ * @example
371
+ * ```ts
372
+ * test("supports serialize/deserialize", () => {
373
+ * const db = Database.open(":memory:");
374
+ * db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)");
375
+ * db.exec('INSERT INTO test (name) VALUES ("Hello")');
376
+ * db.exec('INSERT INTO test (name) VALUES ("World")');
377
+ *
378
+ * const input = db.serialize();
379
+ * const db2 = new Database(input);
380
+ *
381
+ * const stmt = db2.prepare("SELECT * FROM test");
382
+ * expect(JSON.stringify(stmt.get())).toBe(
383
+ * JSON.stringify({
384
+ * id: 1,
385
+ * name: "Hello",
386
+ * }),
387
+ * );
388
+ *
389
+ * expect(JSON.stringify(stmt.all())).toBe(
390
+ * JSON.stringify([
391
+ * {
392
+ * id: 1,
393
+ * name: "Hello",
394
+ * },
395
+ * {
396
+ * id: 2,
397
+ * name: "World",
398
+ * },
399
+ * ]),
400
+ * );
401
+ * db2.exec("insert into test (name) values ('foo')");
402
+ * expect(JSON.stringify(stmt.all())).toBe(
403
+ * JSON.stringify([
404
+ * {
405
+ * id: 1,
406
+ * name: "Hello",
407
+ * },
408
+ * {
409
+ * id: 2,
410
+ * name: "World",
411
+ * },
412
+ * {
413
+ * id: 3,
414
+ * name: "foo",
415
+ * },
416
+ * ]),
417
+ * );
418
+ *
419
+ * const db3 = Database.deserialize(input, true);
420
+ * try {
421
+ * db3.exec("insert into test (name) values ('foo')");
422
+ * throw new Error("Expected error");
423
+ * } catch (e) {
424
+ * expect(e.message).toBe("attempt to write a readonly database");
425
+ * }
426
+ * });
427
+ * ```
428
+ */
429
+ static deserialize(serialized: NodeJS.TypedArray | ArrayBufferLike, isReadOnly?: boolean): Database;
430
+ }
431
+
432
+ /**
433
+ * A prepared statement.
434
+ *
435
+ * This is returned by {@link Database.prepare} and {@link Database.query}.
436
+ *
437
+ * @example
438
+ * ```ts
439
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
440
+ * stmt.all("baz");
441
+ * // => [{bar: "baz"}]
442
+ * ```
443
+ *
444
+ * @example
445
+ * ```ts
446
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
447
+ * stmt.get("baz");
448
+ * // => {bar: "baz"}
449
+ * ```
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
454
+ * stmt.run("baz");
455
+ * // => undefined
456
+ * ```
457
+ */
458
+ export class Statement<ReturnType = unknown, ParamsType extends SQLQueryBindings[] = any[]> {
459
+ /**
460
+ * Creates a new prepared statement from native code.
461
+ *
462
+ * This is used internally by the {@link Database} class. Probably you don't need to call this yourself.
463
+ */
464
+ constructor(nativeHandle: any);
465
+
466
+ /**
467
+ * Execute the prepared statement and return all results as objects.
468
+ *
469
+ * @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.
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
474
+ *
475
+ * stmt.all("baz");
476
+ * // => [{bar: "baz"}]
477
+ *
478
+ * stmt.all();
479
+ * // => [{bar: "baz"}]
480
+ *
481
+ * stmt.all("foo");
482
+ * // => [{bar: "foo"}]
483
+ * ```
484
+ */
485
+ all(...params: ParamsType): ReturnType[];
486
+
487
+ /**
488
+ * Execute the prepared statement and return **the first** result.
489
+ *
490
+ * If no result is returned, this returns `null`.
491
+ *
492
+ * @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.
493
+ *
494
+ * @example
495
+ * ```ts
496
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
497
+ *
498
+ * stmt.all("baz");
499
+ * // => [{bar: "baz"}]
500
+ *
501
+ * stmt.all();
502
+ * // => [{bar: "baz"}]
503
+ *
504
+ * stmt.all("foo");
505
+ * // => [{bar: "foo"}]
506
+ * ```
507
+ *
508
+ * The following types can be used when binding parameters:
509
+ *
510
+ * | JavaScript type | SQLite type |
511
+ * | -------------- | ----------- |
512
+ * | `string` | `TEXT` |
513
+ * | `number` | `INTEGER` or `DECIMAL` |
514
+ * | `boolean` | `INTEGER` (1 or 0) |
515
+ * | `Uint8Array` | `BLOB` |
516
+ * | `Buffer` | `BLOB` |
517
+ * | `bigint` | `INTEGER` |
518
+ * | `null` | `NULL` |
519
+ */
520
+ get(...params: ParamsType): ReturnType | null;
521
+
522
+ /**
523
+ * Execute the prepared statement. This returns `undefined`.
524
+ *
525
+ * @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.
526
+ *
527
+ * @example
528
+ * ```ts
529
+ * const stmt = db.prepare("UPDATE foo SET bar = ?");
530
+ * stmt.run("baz");
531
+ * // => undefined
532
+ *
533
+ * stmt.run();
534
+ * // => undefined
535
+ *
536
+ * stmt.run("foo");
537
+ * // => undefined
538
+ * ```
539
+ *
540
+ * The following types can be used when binding parameters:
541
+ *
542
+ * | JavaScript type | SQLite type |
543
+ * | -------------- | ----------- |
544
+ * | `string` | `TEXT` |
545
+ * | `number` | `INTEGER` or `DECIMAL` |
546
+ * | `boolean` | `INTEGER` (1 or 0) |
547
+ * | `Uint8Array` | `BLOB` |
548
+ * | `Buffer` | `BLOB` |
549
+ * | `bigint` | `INTEGER` |
550
+ * | `null` | `NULL` |
551
+ */
552
+ run(...params: ParamsType): void;
553
+
554
+ /**
555
+ * Execute the prepared statement and return the results as an array of arrays.
556
+ *
557
+ * In Bun v0.6.7 and earlier, this method returned `null` if there were no
558
+ * results instead of `[]`. This was changed in v0.6.8 to align
559
+ * more with what people expect.
560
+ *
561
+ * @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.
562
+ *
563
+ * @example
564
+ * ```ts
565
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
566
+ *
567
+ * stmt.values("baz");
568
+ * // => [['baz']]
569
+ *
570
+ * stmt.values();
571
+ * // => [['baz']]
572
+ *
573
+ * stmt.values("foo");
574
+ * // => [['foo']]
575
+ *
576
+ * stmt.values("not-found");
577
+ * // => []
578
+ * ```
579
+ *
580
+ * The following types can be used when binding parameters:
581
+ *
582
+ * | JavaScript type | SQLite type |
583
+ * | ---------------|-------------|
584
+ * | `string` | `TEXT` |
585
+ * | `number` | `INTEGER` or `DECIMAL` |
586
+ * | `boolean` | `INTEGER` (1 or 0) |
587
+ * | `Uint8Array` | `BLOB` |
588
+ * | `Buffer` | `BLOB` |
589
+ * | `bigint` | `INTEGER` |
590
+ * | `null` | `NULL` |
591
+ */
592
+ values(...params: ParamsType): Array<Array<string | bigint | number | boolean | Uint8Array>>;
593
+
594
+ /**
595
+ * The names of the columns returned by the prepared statement.
596
+ * @example
597
+ * ```ts
598
+ * const stmt = db.prepare("SELECT bar FROM foo WHERE bar = ?");
599
+ *
600
+ * console.log(stmt.columnNames);
601
+ * // => ["bar"]
602
+ * ```
603
+ */
604
+ readonly columnNames: string[];
605
+
606
+ /**
607
+ * The number of parameters expected in the prepared statement.
608
+ * @example
609
+ * ```ts
610
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
611
+ * console.log(stmt.paramsCount);
612
+ * // => 1
613
+ * ```
614
+ * @example
615
+ * ```ts
616
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?");
617
+ * console.log(stmt.paramsCount);
618
+ * // => 2
619
+ * ```
620
+ */
621
+ readonly paramsCount: number;
622
+
623
+ /**
624
+ * Finalize the prepared statement, freeing the resources used by the
625
+ * statement and preventing it from being executed again.
626
+ *
627
+ * This is called automatically when the prepared statement is garbage collected.
628
+ *
629
+ * It is safe to call this multiple times. Calling this on a finalized
630
+ * statement has no effect.
631
+ *
632
+ * Internally, this calls `sqlite3_finalize`.
633
+ */
634
+ finalize(): void;
635
+
636
+ /**
637
+ * Return the expanded SQL string for the prepared statement.
638
+ *
639
+ * Internally, this calls `sqlite3_expanded_sql()` on the underlying `sqlite3_stmt`.
640
+ *
641
+ * @example
642
+ * ```ts
643
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?", "baz");
644
+ * console.log(stmt.toString());
645
+ * // => "SELECT * FROM foo WHERE bar = 'baz'"
646
+ * console.log(stmt);
647
+ * // => "SELECT * FROM foo WHERE bar = 'baz'"
648
+ * ```
649
+ */
650
+ toString(): string;
651
+
652
+ /**
653
+ * Native object representing the underlying `sqlite3_stmt`
654
+ *
655
+ * This is left untyped because the ABI of the native bindings may change at any time.
656
+ */
657
+ readonly native: any;
658
+ }
659
+
660
+ /**
661
+ * Constants from `sqlite3.h`
662
+ *
663
+ * This list isn't exhaustive, but some of the ones which are relevant
664
+ */
665
+ export const constants: {
666
+ /**
667
+ * Open the database as read-only (no write operations, no create).
668
+ * @constant 0x00000001
669
+ */
670
+ SQLITE_OPEN_READONLY: number;
671
+ /**
672
+ * Open the database for reading and writing
673
+ * @constant 0x00000002
674
+ */
675
+ SQLITE_OPEN_READWRITE: number;
676
+ /**
677
+ * Allow creating a new database
678
+ * @constant 0x00000004
679
+ */
680
+ SQLITE_OPEN_CREATE: number;
681
+ /**
682
+ * @constant 0x00000008
683
+ */
684
+ SQLITE_OPEN_DELETEONCLOSE: number;
685
+ /**
686
+ * @constant 0x00000010
687
+ */
688
+ SQLITE_OPEN_EXCLUSIVE: number;
689
+ /**
690
+ * @constant 0x00000020
691
+ */
692
+ SQLITE_OPEN_AUTOPROXY: number;
693
+ /**
694
+ * @constant 0x00000040
695
+ */
696
+ SQLITE_OPEN_URI: number;
697
+ /**
698
+ * @constant 0x00000080
699
+ */
700
+ SQLITE_OPEN_MEMORY: number;
701
+ /**
702
+ * @constant 0x00000100
703
+ */
704
+ SQLITE_OPEN_MAIN_DB: number;
705
+ /**
706
+ * @constant 0x00000200
707
+ */
708
+ SQLITE_OPEN_TEMP_DB: number;
709
+ /**
710
+ * @constant 0x00000400
711
+ */
712
+ SQLITE_OPEN_TRANSIENT_DB: number;
713
+ /**
714
+ * @constant 0x00000800
715
+ */
716
+ SQLITE_OPEN_MAIN_JOURNAL: number;
717
+ /**
718
+ * @constant 0x00001000
719
+ */
720
+ SQLITE_OPEN_TEMP_JOURNAL: number;
721
+ /**
722
+ * @constant 0x00002000
723
+ */
724
+ SQLITE_OPEN_SUBJOURNAL: number;
725
+ /**
726
+ * @constant 0x00004000
727
+ */
728
+ SQLITE_OPEN_SUPER_JOURNAL: number;
729
+ /**
730
+ * @constant 0x00008000
731
+ */
732
+ SQLITE_OPEN_NOMUTEX: number;
733
+ /**
734
+ * @constant 0x00010000
735
+ */
736
+ SQLITE_OPEN_FULLMUTEX: number;
737
+ /**
738
+ * @constant 0x00020000
739
+ */
740
+ SQLITE_OPEN_SHAREDCACHE: number;
741
+ /**
742
+ * @constant 0x00040000
743
+ */
744
+ SQLITE_OPEN_PRIVATECACHE: number;
745
+ /**
746
+ * @constant 0x00080000
747
+ */
748
+ SQLITE_OPEN_WAL: number;
749
+ /**
750
+ * @constant 0x01000000
751
+ */
752
+ SQLITE_OPEN_NOFOLLOW: number;
753
+ /**
754
+ * @constant 0x02000000
755
+ */
756
+ SQLITE_OPEN_EXRESCODE: number;
757
+ /**
758
+ * @constant 0x01
759
+ */
760
+ SQLITE_PREPARE_PERSISTENT: number;
761
+ /**
762
+ * @constant 0x02
763
+ */
764
+ SQLITE_PREPARE_NORMALIZE: number;
765
+ /**
766
+ * @constant 0x04
767
+ */
768
+ SQLITE_PREPARE_NO_VTAB: number;
769
+ };
770
+
771
+ /**
772
+ * The native module implementing the sqlite3 C bindings
773
+ *
774
+ * It is lazily-initialized, so this will return `undefined` until the first
775
+ * call to new Database().
776
+ *
777
+ * The native module makes no gurantees about ABI stability, so it is left
778
+ * untyped
779
+ *
780
+ * If you need to use it directly for some reason, please let us know because
781
+ * that probably points to a deficiency in this API.
782
+ */
783
+ export var native: any;
784
+
785
+ export type SQLQueryBindings =
786
+ | string
787
+ | bigint
788
+ | NodeJS.TypedArray
789
+ | number
790
+ | boolean
791
+ | null
792
+ | Record<string, string | bigint | NodeJS.TypedArray | number | boolean | null>;
793
+
794
+ export default Database;
795
+
796
+ /**
797
+ * Errors from SQLite have a name `SQLiteError`.
798
+ *
799
+ */
800
+ export class SQLiteError extends Error {
801
+ readonly name: "SQLiteError";
802
+
803
+ /**
804
+ * The SQLite3 extended error code
805
+ *
806
+ * This corresponds to `sqlite3_extended_errcode`.
807
+ *
808
+ * @since v1.0.21
809
+ */
810
+ errno: number;
811
+
812
+ /**
813
+ * The name of the SQLite3 error code
814
+ *
815
+ * @example
816
+ * "SQLITE_CONSTRAINT_UNIQUE"
817
+ *
818
+ * @since v1.0.21
819
+ */
820
+ code?: string;
821
+
822
+ /**
823
+ * The UTF-8 byte offset of the sqlite3 query that failed, if known
824
+ *
825
+ * This corresponds to `sqlite3_error_offset`.
826
+ *
827
+ * @since v1.0.21
828
+ */
829
+ readonly byteOffset: number;
830
+ }
831
+ }