-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-generators.d.ts
426 lines (389 loc) · 16.7 KB
/
no-generators.d.ts
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
import sqlite3 from "sqlite3";
export type MigrationOptions = {
/** Whether to set to 'last' to automatically reapply the last migration-file. Default: false */
force?: "last" | false;
/** The name of the database table that is used to keep track. Default: 'migration' */
table?: string;
/** The path of the migration files. Default: './migrations' */
migrationsPath?: string;
};
export type DBOptions = {
/** Path to sqlite database file. Default: './data/sqlite3.db' */
path?: string;
/** Whether to create a db only in memory. Default: false */
memory?: boolean;
/** Whether to open database read-only. Default: false */
readOnly?: boolean;
/** Whether to throw error if database not exists. Default: false */
fileMustExist?: boolean;
/** Whether to automatically enable 'PRAGMA journal_mode = WAL'. Default: true */
WAL?: boolean;
/** Migration options. Disable completely by setting `migrate: false` */
migrate?: MigrationOptions | false;
};
export type DataObject = { [key: string]: any };
/**
* Specifies a where clause.
*
* - Either a string containing the value to use as ID that will be translated to ['id = ?', id]
* - Or an array with a string and the replacements for ? after that. F.e. ['id > ? && name = ?', id, name].
* - Or an object with key values. F.e. {id: params.id}. Or simply an ID that will be translated to ['id = ?', id]
*/
export type WhereClause<T = DataObject> = string | any[] | Partial<T>;
export interface DBInstance {
connection(): Promise<sqlite3.Database>;
prepare(sql: string, ...params: any[]): Promise<Statement>;
exec(sql: string): Promise<void>;
//DB.prototype.pragma = function (source, simplify = false) {
//DB.prototype.checkpoint = function (databaseName) {
//DB.prototype.register = function (...args) {
close(): Promise<void>;
//DB.prototype.defaultSafeIntegers = function (toggleState) {
/**
* Executes the prepared statement. When execution completes it returns an info object describing any changes made. The info object has two properties:
*
* info.changes: The total number of rows that were inserted, updated, or deleted by this operation. Changes made by foreign key actions or trigger programs do not count.
* info.lastInsertROWID: The rowid of the last row inserted into the database (ignoring those caused by trigger programs). If the current statement did not insert any rows into the database, this number should be completely ignored.
*
* If execution of the statement fails, an Error is thrown.
* @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#runbindparameters---object
*
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @returns {object}
*/
run(query: string, ...bindParameters: any[]): Promise<sqlite3.RunResult>;
/**
* Returns all values of a query
* @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#allbindparameters---array-of-rows
*
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @returns {array}
*/
query<RowData = DataObject>(query: string, ...bindParameters: any[]): Promise<RowData[]>;
/**
* Similar to .query(), but instead of returning every row together, an iterator is returned so you can retrieve the rows one by one.
* @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#iteratebindparameters---iterator
*
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @returns {Iterator}
*/
queryIterate<RowData = DataObject>(query: string, ...bindParameters: any[]): Iterable<RowData>;
/**
* Returns the values of the first row of the query-result
* @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#getbindparameters---row
*
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @returns {Object|null}
*/
queryFirstRow<RowData = DataObject>(query: string, ...bindParameters: any[]): Promise<RowData | null>;
/**
* Returns the values of the first row of the query-result
* @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#getbindparameters---row
* It returns always an object and thus can be used with destructuring assignment
*
* @example const {id, name} = DB().queryFirstRowObject(sql)
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @returns {Object}
*/
queryFirstRowObject<RowData = DataObject>(query: string, ...bindParameters: any[]): Promise<RowData | {}>;
/**
* Returns the value of the first column in the first row of the query-result
*
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @returns {any}
*/
queryFirstCell<CellType = any>(query: string, ...bindParameters: any[]): Promise<CellType | undefined>;
/**
* Calls a callback for every row
*
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @param {any} callback the callback that is called
* @returns {integer} count
*/
each<RowData = DataObject>(query: string, p1: any, callback: (row: RowData) => void): Promise<number>;
each<RowData = DataObject>(query: string, p1: any, p2: any, callback: (row: RowData) => void): Promise<number>;
each<RowData = DataObject>(
query: string,
p1: any,
p2: any,
p3: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
query: string,
p1: any,
p2: any,
p3: any,
p4: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
query: string,
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
query: string,
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
query: string,
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
p7: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
query: string,
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
p7: any,
p8: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
query: string,
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
p7: any,
p8: any,
p9: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
query: string,
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
p7: any,
p8: any,
p9: any,
p10: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(query: string, ...bindParameters: any[]): Promise<number>;
/**
* Returns an Array that only contains the values of the specified column
*
* @param {Object} column Name of the column
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @returns {array}
*/
queryColumn<ColumnType = any>(column: string, query: string, ...bindParameters: any[]): Promise<ColumnType[]>;
/**
* Returns a Object that get it key-value-combination from the result of the query
*
* @param {String} key Name of the column that values should be the key
* @param {Object} column Name of the column that values should be the value for the object
* @param {Object} query the SQL-Query that should be run. Can contain placeholders for bind parameters.
* @param {any} bindParameters You can specify bind parameters @see https://github.com/JoshuaWise/better-sqlite3/wiki/API#binding-parameters
* @returns {object}
*/
queryKeyAndColumn<ValueColumnType = any>(
key: string,
column: string,
query: string,
...bindParameters: any[]
): Promise<{ [key: string]: ValueColumnType }>;
/**
* Create an update statement; create more complex one with exec yourself.
*
* @param {String} table Name of the table
* @param {Object} data a Object of data to set. Key is the name of the column. Value 'undefined' is filtered
* @param {String|Array|Object} where required. array with a string and the replacements for ? after that. F.e. ['id > ? && name = ?', id, name]. Or an object with key values. F.e. {id: params.id}. Or simply an ID that will be translated to ['id = ?', id]
* @param {undefined|Array} whiteList optional List of columns that can only be updated with "data"
* @returns {Integer} The number of updated rows
*/
update<RowData = DataObject>(
table: string,
data: Partial<RowData>,
where: WhereClause<RowData>,
whiteList?: string[]
): Promise<number>;
/**
* Create an update statement; create more complex one with exec yourself.
*
* @param {String} table Name of the table
* @param {Object} data a Object of data to set. Key is the name of the column. Value 'undefined' is filtered
* @param {String|Array|Object} where required. array with a string and the replacements for ? after that. F.e. ['id > ? && name = ?', id, name]. Or an object with key values. F.e. {id: params.id}. Or simply an ID that will be translated to ['id = ?', id]
* @param {undefined|Array} whiteBlackList optional List of columns that can not be updated with "data" (blacklist)
* @returns {Integer} The number of updated rows
*/
updateWithBlackList<RowData = DataObject>(
table: string,
data: Partial<RowData>,
where: WhereClause<RowData>,
blackList?: string[]
): Promise<number>;
/**
* Create an insert statement; create more complex one with exec yourself.
*
* @param {String} table Name of the table
* @param {Object|Array} data a Object of data to set. Key is the name of the column. Can be an array of objects.
* @param {undefined|Array} whiteList optional List of columns that only can be updated with "data"
* @returns {Integer} The ID of the last inserted row
*/
insert<RowData = DataObject>(table: string, data: Partial<RowData> | Partial<RowData>[], whiteList?: string[]): Promise<number>;
/**
* Create an insert statement; create more complex one with exec yourself.
*
* @param {String} table Name of the table
* @param {Object|Array} data a Object of data to set. Key is the name of the column. Can be an array of objects.
* @param {undefined|Array} whiteBlackList optional List of columns that can not be updated with "data" (blacklist)
* @returns {Integer} The ID of the last inserted row
*/
insertWithBlackList<RowData = DataObject>(
table: string,
data: Partial<RowData> | Partial<RowData>[],
blackList?: string[]
): Promise<number>;
/**
* Create an replace statement; create more complex one with exec yourself.
*
* @param {String} table Name of the table
* @param {Object|Array} data a Object of data to set. Key is the name of the column. Can be an array of objects.
* @param {undefined|Array} whiteList optional List of columns that only can be updated with "data"
* @returns {Integer} The ID of the last replaced row
*/
replace<RowData = DataObject>(
table: string,
data: Partial<RowData> | Partial<RowData>[],
whiteList?: string[]
): Promise<number>;
/**
* Create an replace statement; create more complex one with exec yourself.
*
* @param {String} table Name of the table
* @param {Object|Array} data a Object of data to set. Key is the name of the column. Can be an array of objects.
* @param {undefined|Array} whiteBlackList optional List of columns that can not be updated with "data" (blacklist)
* @returns {Integer} The ID of the last replaced row
*/
replaceWithBlackList<RowData = DataObject>(
table: string,
data: Partial<RowData> | Partial<RowData>[],
blackList?: string[]
): Promise<number>;
/**
* Create a delete statement; create more complex one with exec yourself.
*
* @param {String} table required. Name of the table
* @param {String|Array|Object} where required. array with a string and the replacements for ? after that. F.e. ['id > ? && name = ?', id, name]. Or an object with key values. F.e. {id: params.id}. Or simply an ID that will be translated to ['id = ?', id]
* @returns {Integer} Number of changed rows
*/
delete<RowData = DataObject>(table: string, where: WhereClause<RowData>): Promise<number>;
/**
* Migrates database schema to the latest version
*/
migrate(options?: MigrationOptions): Promise<void>;
}
interface Statement {
bind(...params: any[]): Promise<void>;
reset(): Promise<void>;
finalize(): Promise<void>;
run(...params: any[]): Promise<sqlite3.RunResult>;
get<RowData = DataObject>(...params: any[]): Promise<RowData | undefined>;
all<RowData = DataObject>(...params: any[]): Promise<RowData[]>;
each<RowData = DataObject>(p1: any, callback: (row: RowData) => void): Promise<number>;
each<RowData = DataObject>(p1: any, p2: any, callback: (row: RowData) => void): Promise<number>;
each<RowData = DataObject>(p1: any, p2: any, p3: any, callback: (row: RowData) => void): Promise<number>;
each<RowData = DataObject>(p1: any, p2: any, p3: any, p4: any, callback: (row: RowData) => void): Promise<number>;
each<RowData = DataObject>(
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
p7: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
p7: any,
p8: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
p7: any,
p8: any,
p9: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(
p1: any,
p2: any,
p3: any,
p4: any,
p5: any,
p6: any,
p7: any,
p8: any,
p9: any,
p10: any,
callback: (row: RowData) => void
): Promise<number>;
each<RowData = DataObject>(...bindParameters: any[]): Promise<number>;
}
declare const DB: { new (options?: DBOptions): DBInstance } & ((options?: DBOptions) => DBInstance);
export default DB;