UNPKG

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