|
1 |
| -import type { BaseDB } from '../types' |
| 1 | +export interface OfficialWasmDB { |
2 | 2 |
|
3 |
| -export type Option = { |
4 |
| - sql: string | string[] |
5 |
| - bind?: any[] | Record<string, any> |
6 |
| - returnValue?: 'resultRows' | 'saveSql' | 'this' |
7 |
| - resultRows?: any[] |
8 |
| - saveSql?: any[] |
9 |
| - columnNames?: string[] |
10 |
| - callback?: (row: any[], stmt: any) => void | false |
11 |
| - rowMode?: 'array' | 'object' | 'stmt' |
12 |
| -} |
| 3 | + /** Returns true if the database handle is open, else false. */ |
| 4 | + isOpen: () => boolean |
| 5 | + |
| 6 | + /** Throws if the given DB has been closed. */ |
| 7 | + affirmOpen: () => this |
| 8 | + |
| 9 | + /** |
| 10 | + * Finalizes all still-open statements which were opened by this object and |
| 11 | + * closes this database connection. This is a no-op if the db has already been |
| 12 | + * closed. After calling `close()`, {@link pointer} will resolve to |
| 13 | + * `undefined`, so that can be used to check whether the db instance is still |
| 14 | + * opened. |
| 15 | + * |
| 16 | + * If {@link onclose.before} is a function then it is called before any |
| 17 | + * close-related cleanup. If {@link onclose.after} is a function then it is |
| 18 | + * called after the db is closed but before auxiliary state like this.filename |
| 19 | + * is cleared. |
| 20 | + * |
| 21 | + * Both onclose handlers are passed this object as their only argument. If |
| 22 | + * this db is not opened, neither of the handlers are called. Any exceptions |
| 23 | + * the handlers throw are ignored because "destructors must not throw." |
| 24 | + * |
| 25 | + * Note that garbage collection of a db handle, if it happens at all, will |
| 26 | + * never trigger `close()`, so {@link onclose} handlers are not a reliable way |
| 27 | + * to implement close-time cleanup or maintenance of a db. |
| 28 | + */ |
| 29 | + close: () => void // ✓ |
| 30 | + |
| 31 | + /** |
| 32 | + * Returns the number of changes, as per `sqlite3_changes()` (if the first |
| 33 | + * argument is `false`) or `sqlite3_total_changes()` (if it's `true`). If the |
| 34 | + * 2nd argument is `true`, it uses `sqlite3_changes64()` or |
| 35 | + * `sqlite3_total_changes64()`, which will trigger an exception if this build |
| 36 | + * does not have `BigInt` support enabled. |
| 37 | + */ |
| 38 | + changes: (total?: boolean, sixtyFour?: boolean) => number |
| 39 | + |
| 40 | + /** |
| 41 | + * Prepares the given SQL, `step()`s it one time, and returns an array |
| 42 | + * containing the values of the first result row. If it has no results, |
| 43 | + * `undefined` is returned. If passed a second argument other than |
| 44 | + * `undefined`, it is treated like an argument to |
| 45 | + * {@link PreparedStatement#bind}, so may be any type supported by that |
| 46 | + * function. Throws on error. |
| 47 | + */ |
| 48 | + selectArray: (sql: string, bind?: any[]) => any[] | undefined |
| 49 | + |
| 50 | + /** |
| 51 | + * Works identically to {@link Database#selectArrays} except that each value in |
| 52 | + * the returned array is an object, as per the `"object"` rowMode option to |
| 53 | + * {@link Database#exec}. |
| 54 | + */ |
| 55 | + selectObjects: ( |
| 56 | + sql: string, |
| 57 | + bind?: any[], |
| 58 | + ) => { [columnName: string]: any }[] |
13 | 59 |
|
14 |
| -export interface OfficialWasmDB extends BaseDB { |
15 |
| - changes: (isTotal: boolean, isBigint: boolean) => number | bigint |
16 |
| - selectArray: (sql: string, bind?: any[]) => any[] |
17 |
| - selectObjects: (sql: string, bind?: any[]) => any[] |
18 | 60 | }
|
0 commit comments