UNPKG

5.62 kBTypeScriptView Raw
1import * as sqlite from 'sqlite3';
2import { ISqlite } from './interfaces';
3/**
4 * Promisified wrapper for the sqlite3#Statement interface.
5 */
6export declare class Statement<S extends sqlite.Statement = sqlite.Statement> {
7 stmt: S;
8 constructor(stmt: S);
9 /**
10 * Returns the underlying sqlite3 Statement instance
11 */
12 getStatementInstance(): S;
13 /**
14 * Binds parameters to the prepared statement.
15 *
16 * Binding parameters with this function completely resets the statement object and row cursor
17 * and removes all previously bound parameters, if any.
18 */
19 bind(...params: any[]): Promise<void>;
20 /**
21 * Resets the row cursor of the statement and preserves the parameter bindings.
22 * Use this function to re-execute the same query with the same bindings.
23 */
24 reset(): Promise<void>;
25 /**
26 * Finalizes the statement. This is typically optional, but if you experience long delays before
27 * the next query is executed, explicitly finalizing your statement might be necessary.
28 * This might be the case when you run an exclusive query (see section Control Flow).
29 * After the statement is finalized, all further function calls on that statement object
30 * will throw errors.
31 */
32 finalize(): Promise<void>;
33 /**
34 * Binds parameters and executes the statement.
35 *
36 * If you specify bind parameters, they will be bound to the statement before it is executed.
37 * Note that the bindings and the row cursor are reset when you specify even a single bind parameter.
38 *
39 * The execution behavior is identical to the Database#run method with the difference that the
40 * statement will not be finalized after it is run. This means you can run it multiple times.
41 *
42 * @param {any} [params, ...] When the SQL statement contains placeholders, you
43 * can pass them in here. They will be bound to the statement before it is
44 * executed. There are three ways of passing bind parameters: directly in
45 * the function's arguments, as an array, and as an object for named
46 * parameters. This automatically sanitizes inputs.
47 */
48 run(...params: any[]): Promise<ISqlite.RunResult>;
49 /**
50 * Binds parameters, executes the statement and retrieves the first result row.
51 * The parameters are the same as the Statement#run function, with the following differences:
52 *
53 * Using this method can leave the database locked, as the database awaits further
54 * calls to Statement#get to retrieve subsequent rows. To inform the database that you
55 * are finished retrieving rows, you should either finalize (with Statement#finalize)
56 * or reset (with Statement#reset) the statement.
57 *
58 * @param {any} [params, ...] When the SQL statement contains placeholders, you
59 * can pass them in here. They will be bound to the statement before it is
60 * executed. There are three ways of passing bind parameters: directly in
61 * the function's arguments, as an array, and as an object for named
62 * parameters. This automatically sanitizes inputs.
63 */
64 get<T = any>(...params: any[]): Promise<T | undefined>;
65 /**
66 * Binds parameters, executes the statement and calls the callback with all result rows.
67 * The parameters are the same as the Statement#run function, with the following differences:
68 *
69 * If the result set is empty, it will resolve to an empty array, otherwise it contains an
70 * object for each result row which in turn contains the values of that row.
71 * Like with Statement#run, the statement will not be finalized after executing this function.
72 *
73 * @param {any} [params, ...] When the SQL statement contains placeholders, you
74 * can pass them in here. They will be bound to the statement before it is
75 * executed. There are three ways of passing bind parameters: directly in
76 * the function's arguments, as an array, and as an object for named
77 * parameters. This automatically sanitizes inputs.
78 *
79 * @see https://github.com/mapbox/node-sqlite3/wiki/API#databaseallsql-param--callback
80 */
81 all<T = any[]>(...params: any[]): Promise<T>;
82 /**
83 * Binds parameters, executes the statement and calls the callback for each result row.
84 *
85 * If the result set succeeds but is empty, the callback is never called.
86 * In all other cases, the callback is called once for every retrieved row.
87 * The order of calls correspond exactly to the order of rows in the result set.
88 *
89 * Like with Statement#run, the statement will not be finalized after executing this function.
90 *
91 * There is currently no way to abort execution!
92 *
93 * The last parameter to each() *must* be a callback function, where the first parameter will
94 * be the returned row.
95 *
96 * @example await stmt.each('someParamValue', (err, row) => {
97 * // row contains the row data
98 * // each() resolves when there are no more rows to fetch
99 * })
100 *
101 * @see https://github.com/mapbox/node-sqlite3/wiki/API#statementeachparam--callback-complete
102 * @returns Promise<number> Number of rows returned
103 */
104 each<T = any>(callback: (err: any, row: T) => void): Promise<number>;
105 each<T = any>(param1: any, callback: (err: any, row: T) => void): Promise<number>;
106 each<T = any>(param1: any, param2: any, callback: (err: any, row: T) => void): Promise<number>;
107 each<T = any>(param1: any, param2: any, param3: any, callback: (err: any, row: T) => void): Promise<number>;
108 each<T = any>(...params: any[]): Promise<number>;
109}
110
\No newline at end of file