Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | 3x 71x 1x 1x 1x 1x 7x 7x 7x 7x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Statement } from 'sqlite3' import { Sqlite3 } from '../interfaces/Sqlite3.interfaces' export class Sqlite3Statement { stmt: Statement constructor (stmt: Statement) { this.stmt = stmt } /** * Returns the underlying sqlite3 Statement instance */ getStatementInstance (): Statement { return this.stmt } /** * Binds parameters to the prepared statement. * * Binding parameters with this function completely resets the statement object and row cursor * and removes all previously bound parameters, if any. */ bind (...params: any[]): Promise<void> { return new Promise((resolve, reject) => { this.stmt.bind(...params, err => { Iif (err) { return reject(err) } resolve() }) }) } /** * Resets the row cursor of the statement and preserves the parameter bindings. * Use this function to re-execute the same query with the same bindings. */ reset (): Promise<void> { return new Promise(resolve => { this.stmt.reset(() => { resolve() }) }) } /** * Finalizes the statement. This is typically optional, but if you experience long delays before * the next query is executed, explicitly finalizing your statement might be necessary. * This might be the case when you run an exclusive query (see section Control Flow). * After the statement is finalized, all further function calls on that statement object * will throw errors. */ finalize (): Promise<void> { return new Promise((resolve, reject) => { this.stmt.finalize(err => { Iif (err) { return reject(err) } resolve() }) }) } /** * Binds parameters and executes the statement. * * If you specify bind parameters, they will be bound to the statement before it is executed. * Note that the bindings and the row cursor are reset when you specify even a single bind parameter. * * The execution behavior is identical to the Database#run method with the difference that the * statement will not be finalized after it is run. This means you can run it multiple times. * * @param {any} [params, ...] When the SQL statement contains placeholders, you * can pass them in here. They will be bound to the statement before it is * executed. There are three ways of passing bind parameters: directly in * the function's arguments, as an array, and as an object for named * parameters. This automatically sanitizes inputs. */ run (...params: any[]): Promise<Sqlite3.RunResult> { return new Promise((resolve, reject) => { const stmt = this this.stmt.run(...params, function (err) { Iif (err) { return reject(err) } resolve({ stmt, lastID: this.lastID, changes: this.changes }) }) }) } /** * Binds parameters, executes the statement and retrieves the first result row. * The parameters are the same as the Statement#run function, with the following differences: * * Using this method can leave the database locked, as the database awaits further * calls to Statement#get to retrieve subsequent rows. To inform the database that you * are finished retrieving rows, you should either finalize (with Statement#finalize) * or reset (with Statement#reset) the statement. * * @param {any} [params, ...] When the SQL statement contains placeholders, you * can pass them in here. They will be bound to the statement before it is * executed. There are three ways of passing bind parameters: directly in * the function's arguments, as an array, and as an object for named * parameters. This automatically sanitizes inputs. */ get<T = any> (...params: any[]): Promise<T | undefined> { return new Promise((resolve, reject) => { this.stmt.get(...params, (err, row?: T) => { Iif (err) { return reject(err) } resolve(row) }) }) } /** * Binds parameters, executes the statement and calls the callback with all result rows. * The parameters are the same as the Statement#run function, with the following differences: * * If the result set is empty, it will resolve to an empty array, otherwise it contains an * object for each result row which in turn contains the values of that row. * Like with Statement#run, the statement will not be finalized after executing this function. * * @param {any} [params, ...] When the SQL statement contains placeholders, you * can pass them in here. They will be bound to the statement before it is * executed. There are three ways of passing bind parameters: directly in * the function's arguments, as an array, and as an object for named * parameters. This automatically sanitizes inputs. * * @see https://github.com/mapbox/node-sqlite3/wiki/API#databaseallsql-param--callback */ all<T = any[]> (...params: any[]): Promise<T> { return new Promise((resolve, reject) => { this.stmt.all(...params, (err, rows?: T) => { Iif (err) { return reject(err) } resolve(rows) }) }) } /** * Binds parameters, executes the statement and calls the callback for each result row. * * If the result set succeeds but is empty, the callback is never called. * In all other cases, the callback is called once for every retrieved row. * The order of calls correspond exactly to the order of rows in the result set. * * Like with Statement#run, the statement will not be finalized after executing this function. * * There is currently no way to abort execution! * * The last parameter to each() *must* be a callback function, where the first parameter will * be the returned row. * * @example await stmt.each('someParamValue', (err, row) => { * // row contains the row data * // each() resolves when there are no more rows to fetch * }) * * @see https://github.com/mapbox/node-sqlite3/wiki/API#statementeachparam--callback-complete * @returns Promise<number> Number of rows returned */ each<T = any> (...params: any[]): Promise<number> { return new Promise((resolve, reject) => { const callback: (err, row: T) => void = params.pop() Iif (!callback || typeof callback !== 'function') { throw new Error( 'Last param of Sqlite3Statement#each() must be a callback function' ) } this.stmt.each( ...params, (err, row) => { Iif (err) { return callback(err, null) } callback(null, row) }, (err, count) => { Iif (err) { return reject(err) } resolve(count) } ) }) } } |