|
| 1 | +/* |
| 2 | +Types for the NPM package `sqlite3`. |
| 3 | + |
| 4 | +Based on upstream API docs: |
| 5 | + https://github.com/mapbox/node-sqlite3/wiki/API |
| 6 | + |
| 7 | +@flow strict-local |
| 8 | +*/ |
| 9 | + |
| 10 | +/* eslint-disable */ |
| 11 | + |
| 12 | +// From `Statement::BindParameter` in the implementation. |
| 13 | +// It actually also accepts arbitrary objects using ToString, |
| 14 | +// but let's say that it doesn't. |
| 15 | +export type QueryParameter = string | number | boolean | null | RegExp | Date | Buffer; |
| 16 | + |
| 17 | +type Row = { ... }; |
| 18 | + |
| 19 | +type ResultCallback<T> = interface { (Error): void, (null, T): void }; |
| 20 | + |
| 21 | +declare export class Database { |
| 22 | + constructor(filename: string): this; // not modeled: mode and callback |
| 23 | + |
| 24 | + close(cb?: ResultCallback<void>): void; |
| 25 | + |
| 26 | + // configure(…) not modeled |
| 27 | + |
| 28 | + // Does the `run` callback get a second argument? Not sure from docs. |
| 29 | + // Not modeled here: the `this` on the `run` callback. |
| 30 | + run(sql: string, params: QueryParameter[], cb?: ResultCallback<void>): this; |
| 31 | + run(sql: string, cb?: ResultCallback<void>): this; |
| 32 | + |
| 33 | + get(sql: string, params: QueryParameter[], cb?: ResultCallback<Row | void>): this; |
| 34 | + get(sql: string, cb?: ResultCallback<Row | void>): this; |
| 35 | + |
| 36 | + all(sql: string, params: QueryParameter[], cb?: ResultCallback<Row[]>): this; |
| 37 | + all(sql: string, cb?: ResultCallback<Row[]>): this; |
| 38 | + |
| 39 | + each( |
| 40 | + sql: string, |
| 41 | + params: QueryParameter[], |
| 42 | + cb?: ResultCallback<Row>, |
| 43 | + complete?: ResultCallback<number>, |
| 44 | + ): this; |
| 45 | + each(sql: string, cb?: ResultCallback<Row>, complete?: ResultCallback<number>): this; |
| 46 | + |
| 47 | + exec(sql: string, cb?: ResultCallback<void>): this; |
| 48 | + |
| 49 | + // Not modeled: the Statement class, and: |
| 50 | + // prepare(sql: string, params: QueryParameter[], cb?: ResultCallback<void>): Statement; |
| 51 | + // prepare(sql: string, cb?: ResultCallback<void>): Statement; |
| 52 | + |
| 53 | + // The library also accepts forms one might write like: |
| 54 | + // all(sql: string, ...params: QueryParameter[], cb?: ResultCallback<Row[]>): this |
| 55 | + // with the query parameters splatted right into the arguments list. |
| 56 | + // But that means a variable-length list of arguments followed by another |
| 57 | + // argument, which the Flow type system doesn't permit. We include the |
| 58 | + // zero-argument version of that for convenience; otherwise, pass an array. |
| 59 | + // |
| 60 | + // It also accepts `params` as an object like this: |
| 61 | + // db.run("UPDATE tbl SET name = $name WHERE id = $id", { $id: 2, $name: "bar" }); |
| 62 | + // We leave that out for now. |
| 63 | +} |
| 64 | + |
| 65 | +export default { |
| 66 | + // `verbose` function not modeled |
| 67 | + Database, |
| 68 | + // Statement class not modeled |
| 69 | +}; |
0 commit comments