@tursodatabase/database-common 0.6.0-pre.9 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compat.d.ts +3 -2
- package/dist/compat.d.ts.map +1 -1
- package/dist/compat.js +39 -6
- package/dist/promise.d.ts +34 -3
- package/dist/promise.d.ts.map +1 -1
- package/dist/promise.js +99 -7
- package/dist/types.d.ts +13 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/compat.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeDatabase, NativeStatement } from "./types.js";
|
|
1
|
+
import { NativeDatabase, NativeStatement, QueryOptions } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Database represents a connection that can prepare and execute SQL statements.
|
|
4
4
|
*/
|
|
@@ -19,6 +19,7 @@ declare class Database {
|
|
|
19
19
|
* @param {boolean} [opts.readonly=false] - Open the database in read-only mode.
|
|
20
20
|
* @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
|
|
21
21
|
* @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
|
|
22
|
+
* @param {number} [opts.defaultQueryTimeout=0] - Default maximum query execution time in milliseconds before interruption.
|
|
22
23
|
*/
|
|
23
24
|
constructor(db: NativeDatabase);
|
|
24
25
|
/**
|
|
@@ -47,7 +48,7 @@ declare class Database {
|
|
|
47
48
|
*
|
|
48
49
|
* @param {string} sql - The string containing SQL statements to execute
|
|
49
50
|
*/
|
|
50
|
-
exec(sql: any): void;
|
|
51
|
+
exec(sql: any, queryOptions?: QueryOptions): void;
|
|
51
52
|
/**
|
|
52
53
|
* Interrupts the database connection.
|
|
53
54
|
*/
|
package/dist/compat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../compat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cA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AAc;IAKrD;;;;OAIG;IACH,GAAG,CAAC,GAAG,KAAA;IAKP;;;;OAIG;IACH,KAAK,CAAC,SAAS,KAAA;IAKf;;;;OAIG;IACH,YAAY,CAAC,MAAM,KAAA;IAKnB;;;;OAIG;IACH,OAAO;IAIP,IAAI,MAAM,SAET;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,QAAQ,mBAEX;IAED;;OAEG;IACH,GAAG,CAAC,GAAG,cAAc,OAAA;;;;IA4BrB;;;;OAIG;IACH,GAAG,CAAC,GAAG,cAAc,OAAA;IAsBrB;;;;OAIG;IACF,OAAO,CAAC,GAAG,cAAc,OAAA;IAqB1B;;;;OAIG;IACH,GAAG,CAAC,GAAG,cAAc,OAAA;IAsBrB;;OAEG;IACH,SAAS;IAKT;;;;;OAKG;IACH,IAAI,CAAC,GAAG,cAAc,OAAA;IAStB,KAAK;CAGN;AAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAA"}
|
package/dist/compat.js
CHANGED
|
@@ -16,6 +16,30 @@ function createErrorByName(name, message) {
|
|
|
16
16
|
}
|
|
17
17
|
return new ErrorConstructor(message);
|
|
18
18
|
}
|
|
19
|
+
function isQueryOptions(value) {
|
|
20
|
+
return value != null
|
|
21
|
+
&& typeof value === "object"
|
|
22
|
+
&& !Array.isArray(value)
|
|
23
|
+
&& Object.prototype.hasOwnProperty.call(value, "queryTimeout");
|
|
24
|
+
}
|
|
25
|
+
function splitBindParameters(bindParameters) {
|
|
26
|
+
if (bindParameters.length === 0) {
|
|
27
|
+
return { params: undefined, queryOptions: undefined };
|
|
28
|
+
}
|
|
29
|
+
if (bindParameters.length > 1 && isQueryOptions(bindParameters[bindParameters.length - 1])) {
|
|
30
|
+
return {
|
|
31
|
+
params: bindParameters.length === 2 ? bindParameters[0] : bindParameters.slice(0, -1),
|
|
32
|
+
queryOptions: bindParameters[bindParameters.length - 1],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return { params: bindParameters.length === 1 ? bindParameters[0] : bindParameters, queryOptions: undefined };
|
|
36
|
+
}
|
|
37
|
+
function toBindArgs(params) {
|
|
38
|
+
if (params === undefined) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return [params];
|
|
42
|
+
}
|
|
19
43
|
/**
|
|
20
44
|
* Database represents a connection that can prepare and execute SQL statements.
|
|
21
45
|
*/
|
|
@@ -36,6 +60,7 @@ class Database {
|
|
|
36
60
|
* @param {boolean} [opts.readonly=false] - Open the database in read-only mode.
|
|
37
61
|
* @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
|
|
38
62
|
* @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
|
|
63
|
+
* @param {number} [opts.defaultQueryTimeout=0] - Default maximum query execution time in milliseconds before interruption.
|
|
39
64
|
*/
|
|
40
65
|
constructor(db) {
|
|
41
66
|
this.db = db;
|
|
@@ -150,11 +175,11 @@ class Database {
|
|
|
150
175
|
*
|
|
151
176
|
* @param {string} sql - The string containing SQL statements to execute
|
|
152
177
|
*/
|
|
153
|
-
exec(sql) {
|
|
178
|
+
exec(sql, queryOptions) {
|
|
154
179
|
if (!this.open) {
|
|
155
180
|
throw new TypeError("The database connection is not open");
|
|
156
181
|
}
|
|
157
|
-
const exec = this.db.executor(sql);
|
|
182
|
+
const exec = this.db.executor(sql, queryOptions);
|
|
158
183
|
try {
|
|
159
184
|
while (true) {
|
|
160
185
|
const stepResult = exec.stepSync();
|
|
@@ -255,8 +280,10 @@ class Statement {
|
|
|
255
280
|
*/
|
|
256
281
|
run(...bindParameters) {
|
|
257
282
|
const totalChangesBefore = this.db.totalChanges();
|
|
283
|
+
const { params, queryOptions } = splitBindParameters(bindParameters);
|
|
258
284
|
this.stmt.reset();
|
|
259
|
-
|
|
285
|
+
this.stmt.setQueryTimeout(queryOptions);
|
|
286
|
+
bindParams(this.stmt, toBindArgs(params));
|
|
260
287
|
for (;;) {
|
|
261
288
|
const stepResult = this.stmt.stepSync();
|
|
262
289
|
if (stepResult === STEP_IO) {
|
|
@@ -281,8 +308,10 @@ class Statement {
|
|
|
281
308
|
* @param bindParameters - The bind parameters for executing the statement.
|
|
282
309
|
*/
|
|
283
310
|
get(...bindParameters) {
|
|
311
|
+
const { params, queryOptions } = splitBindParameters(bindParameters);
|
|
284
312
|
this.stmt.reset();
|
|
285
|
-
|
|
313
|
+
this.stmt.setQueryTimeout(queryOptions);
|
|
314
|
+
bindParams(this.stmt, toBindArgs(params));
|
|
286
315
|
let row = undefined;
|
|
287
316
|
for (;;) {
|
|
288
317
|
const stepResult = this.stmt.stepSync();
|
|
@@ -305,8 +334,10 @@ class Statement {
|
|
|
305
334
|
* @param bindParameters - The bind parameters for executing the statement.
|
|
306
335
|
*/
|
|
307
336
|
*iterate(...bindParameters) {
|
|
337
|
+
const { params, queryOptions } = splitBindParameters(bindParameters);
|
|
308
338
|
this.stmt.reset();
|
|
309
|
-
|
|
339
|
+
this.stmt.setQueryTimeout(queryOptions);
|
|
340
|
+
bindParams(this.stmt, toBindArgs(params));
|
|
310
341
|
while (true) {
|
|
311
342
|
const stepResult = this.stmt.stepSync();
|
|
312
343
|
if (stepResult === STEP_IO) {
|
|
@@ -327,8 +358,10 @@ class Statement {
|
|
|
327
358
|
* @param bindParameters - The bind parameters for executing the statement.
|
|
328
359
|
*/
|
|
329
360
|
all(...bindParameters) {
|
|
361
|
+
const { params, queryOptions } = splitBindParameters(bindParameters);
|
|
330
362
|
this.stmt.reset();
|
|
331
|
-
|
|
363
|
+
this.stmt.setQueryTimeout(queryOptions);
|
|
364
|
+
bindParams(this.stmt, toBindArgs(params));
|
|
332
365
|
const rows = [];
|
|
333
366
|
for (;;) {
|
|
334
367
|
const stepResult = this.stmt.stepSync();
|
package/dist/promise.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncLock } from "./async-lock.js";
|
|
2
|
-
import { NativeDatabase, NativeStatement } from "./types.js";
|
|
2
|
+
import { NativeDatabase, NativeStatement, QueryOptions } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Database represents a connection that can prepare and execute SQL statements.
|
|
5
5
|
*/
|
|
@@ -24,13 +24,44 @@ declare class Database {
|
|
|
24
24
|
*
|
|
25
25
|
* @param {string} sql - The SQL statement string to prepare.
|
|
26
26
|
*/
|
|
27
|
-
prepare(sql:
|
|
27
|
+
prepare(sql: string): Promise<Statement>;
|
|
28
28
|
/**
|
|
29
29
|
* Returns a function that executes the given function in a transaction.
|
|
30
30
|
*
|
|
31
31
|
* @param {function} fn - The function to wrap in a transaction.
|
|
32
32
|
*/
|
|
33
33
|
transaction(fn: (...any: any[]) => Promise<any>): (...bindParameters: any[]) => Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Prepares the SQL and executes it as `Statement.run`, returning the run info.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} sql - The SQL statement string.
|
|
38
|
+
* @param {...any} bindParameters - Bind parameters, optionally followed by a query options object.
|
|
39
|
+
*/
|
|
40
|
+
run(sql: any, ...bindParameters: any[]): Promise<{
|
|
41
|
+
changes: number;
|
|
42
|
+
lastInsertRowid: number;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Prepares the SQL and executes it as `Statement.get`, returning the first row.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} sql - The SQL statement string.
|
|
48
|
+
* @param {...any} bindParameters - Bind parameters, optionally followed by a query options object.
|
|
49
|
+
*/
|
|
50
|
+
get(sql: any, ...bindParameters: any[]): Promise<any>;
|
|
51
|
+
/**
|
|
52
|
+
* Prepares the SQL and executes it as `Statement.all`, returning all rows.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} sql - The SQL statement string.
|
|
55
|
+
* @param {...any} bindParameters - Bind parameters, optionally followed by a query options object.
|
|
56
|
+
*/
|
|
57
|
+
all(sql: any, ...bindParameters: any[]): Promise<any[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Prepares the SQL and executes it as `Statement.iterate`, yielding each row.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} sql - The SQL statement string.
|
|
62
|
+
* @param {...any} bindParameters - Bind parameters, optionally followed by a query options object.
|
|
63
|
+
*/
|
|
64
|
+
iterate(sql: any, ...bindParameters: any[]): AsyncGenerator<any, void, unknown>;
|
|
34
65
|
pragma(source: any, options: any): Promise<any[]>;
|
|
35
66
|
backup(filename: any, options: any): void;
|
|
36
67
|
serialize(options: any): void;
|
|
@@ -45,7 +76,7 @@ declare class Database {
|
|
|
45
76
|
*
|
|
46
77
|
* @param {string} sql - The string containing SQL statements to execute
|
|
47
78
|
*/
|
|
48
|
-
exec(sql: any): Promise<void>;
|
|
79
|
+
exec(sql: any, queryOptions?: QueryOptions): Promise<void>;
|
|
49
80
|
/**
|
|
50
81
|
* Interrupts the database connection.
|
|
51
82
|
*/
|
package/dist/promise.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAE,eAAe,EAA8C,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAA8C,MAAM,YAAY,CAAC;AAoDvH;;GAEG;AACH,cAAM,QAAQ;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IAEvB,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,QAAQ,CAAY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,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/promise.js
CHANGED
|
@@ -17,6 +17,30 @@ function createErrorByName(name, message) {
|
|
|
17
17
|
}
|
|
18
18
|
return new ErrorConstructor(message);
|
|
19
19
|
}
|
|
20
|
+
function isQueryOptions(value) {
|
|
21
|
+
return value != null
|
|
22
|
+
&& typeof value === "object"
|
|
23
|
+
&& !Array.isArray(value)
|
|
24
|
+
&& Object.prototype.hasOwnProperty.call(value, "queryTimeout");
|
|
25
|
+
}
|
|
26
|
+
function splitBindParameters(bindParameters) {
|
|
27
|
+
if (bindParameters.length === 0) {
|
|
28
|
+
return { params: undefined, queryOptions: undefined };
|
|
29
|
+
}
|
|
30
|
+
if (bindParameters.length > 1 && isQueryOptions(bindParameters[bindParameters.length - 1])) {
|
|
31
|
+
return {
|
|
32
|
+
params: bindParameters.length === 2 ? bindParameters[0] : bindParameters.slice(0, -1),
|
|
33
|
+
queryOptions: bindParameters[bindParameters.length - 1],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return { params: bindParameters.length === 1 ? bindParameters[0] : bindParameters, queryOptions: undefined };
|
|
37
|
+
}
|
|
38
|
+
function toBindArgs(params) {
|
|
39
|
+
if (params === undefined) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return [params];
|
|
43
|
+
}
|
|
20
44
|
/**
|
|
21
45
|
* Database represents a connection that can prepare and execute SQL statements.
|
|
22
46
|
*/
|
|
@@ -118,6 +142,66 @@ class Database {
|
|
|
118
142
|
Object.defineProperties(properties.exclusive.value, properties);
|
|
119
143
|
return properties.default.value;
|
|
120
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Prepares the SQL and executes it as `Statement.run`, returning the run info.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} sql - The SQL statement string.
|
|
149
|
+
* @param {...any} bindParameters - Bind parameters, optionally followed by a query options object.
|
|
150
|
+
*/
|
|
151
|
+
async run(sql, ...bindParameters) {
|
|
152
|
+
const stmt = await this.prepare(sql);
|
|
153
|
+
try {
|
|
154
|
+
return await stmt.run(...bindParameters);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await stmt.close();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Prepares the SQL and executes it as `Statement.get`, returning the first row.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} sql - The SQL statement string.
|
|
164
|
+
* @param {...any} bindParameters - Bind parameters, optionally followed by a query options object.
|
|
165
|
+
*/
|
|
166
|
+
async get(sql, ...bindParameters) {
|
|
167
|
+
const stmt = await this.prepare(sql);
|
|
168
|
+
try {
|
|
169
|
+
return await stmt.get(...bindParameters);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
await stmt.close();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Prepares the SQL and executes it as `Statement.all`, returning all rows.
|
|
177
|
+
*
|
|
178
|
+
* @param {string} sql - The SQL statement string.
|
|
179
|
+
* @param {...any} bindParameters - Bind parameters, optionally followed by a query options object.
|
|
180
|
+
*/
|
|
181
|
+
async all(sql, ...bindParameters) {
|
|
182
|
+
const stmt = await this.prepare(sql);
|
|
183
|
+
try {
|
|
184
|
+
return await stmt.all(...bindParameters);
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
await stmt.close();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Prepares the SQL and executes it as `Statement.iterate`, yielding each row.
|
|
192
|
+
*
|
|
193
|
+
* @param {string} sql - The SQL statement string.
|
|
194
|
+
* @param {...any} bindParameters - Bind parameters, optionally followed by a query options object.
|
|
195
|
+
*/
|
|
196
|
+
async *iterate(sql, ...bindParameters) {
|
|
197
|
+
const stmt = await this.prepare(sql);
|
|
198
|
+
try {
|
|
199
|
+
yield* stmt.iterate(...bindParameters);
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
await stmt.close();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
121
205
|
async pragma(source, options) {
|
|
122
206
|
if (options == null)
|
|
123
207
|
options = {};
|
|
@@ -126,7 +210,7 @@ class Database {
|
|
|
126
210
|
if (typeof options !== "object")
|
|
127
211
|
throw new TypeError("Expected second argument to be an options object");
|
|
128
212
|
const pragma = `PRAGMA ${source}`;
|
|
129
|
-
const stmt = this.prepare(pragma);
|
|
213
|
+
const stmt = await this.prepare(pragma);
|
|
130
214
|
try {
|
|
131
215
|
const results = await stmt.all();
|
|
132
216
|
return results;
|
|
@@ -162,12 +246,12 @@ class Database {
|
|
|
162
246
|
*
|
|
163
247
|
* @param {string} sql - The string containing SQL statements to execute
|
|
164
248
|
*/
|
|
165
|
-
async exec(sql) {
|
|
249
|
+
async exec(sql, queryOptions) {
|
|
166
250
|
if (!this.open) {
|
|
167
251
|
throw new TypeError("The database connection is not open");
|
|
168
252
|
}
|
|
169
253
|
await this.execLock.acquire();
|
|
170
|
-
const exec = this.db.executor(sql);
|
|
254
|
+
const exec = this.db.executor(sql, queryOptions);
|
|
171
255
|
try {
|
|
172
256
|
while (true) {
|
|
173
257
|
const stepResult = exec.stepSync();
|
|
@@ -319,7 +403,9 @@ class Statement {
|
|
|
319
403
|
*/
|
|
320
404
|
async run(...bindParameters) {
|
|
321
405
|
let stmt = await this.stmt.resolve();
|
|
322
|
-
|
|
406
|
+
const { params, queryOptions } = splitBindParameters(bindParameters);
|
|
407
|
+
stmt.setQueryTimeout(queryOptions);
|
|
408
|
+
bindParams(stmt, toBindArgs(params));
|
|
323
409
|
const totalChangesBefore = this.db.totalChanges();
|
|
324
410
|
await this.execLock.acquire();
|
|
325
411
|
try {
|
|
@@ -353,7 +439,9 @@ class Statement {
|
|
|
353
439
|
*/
|
|
354
440
|
async get(...bindParameters) {
|
|
355
441
|
let stmt = await this.stmt.resolve();
|
|
356
|
-
|
|
442
|
+
const { params, queryOptions } = splitBindParameters(bindParameters);
|
|
443
|
+
stmt.setQueryTimeout(queryOptions);
|
|
444
|
+
bindParams(stmt, toBindArgs(params));
|
|
357
445
|
await this.execLock.acquire();
|
|
358
446
|
let row = undefined;
|
|
359
447
|
try {
|
|
@@ -385,7 +473,9 @@ class Statement {
|
|
|
385
473
|
*/
|
|
386
474
|
async *iterate(...bindParameters) {
|
|
387
475
|
let stmt = await this.stmt.resolve();
|
|
388
|
-
|
|
476
|
+
const { params, queryOptions } = splitBindParameters(bindParameters);
|
|
477
|
+
stmt.setQueryTimeout(queryOptions);
|
|
478
|
+
bindParams(stmt, toBindArgs(params));
|
|
389
479
|
await this.execLock.acquire();
|
|
390
480
|
try {
|
|
391
481
|
while (true) {
|
|
@@ -414,7 +504,9 @@ class Statement {
|
|
|
414
504
|
*/
|
|
415
505
|
async all(...bindParameters) {
|
|
416
506
|
let stmt = await this.stmt.resolve();
|
|
417
|
-
|
|
507
|
+
const { params, queryOptions } = splitBindParameters(bindParameters);
|
|
508
|
+
stmt.setQueryTimeout(queryOptions);
|
|
509
|
+
bindParams(stmt, toBindArgs(params));
|
|
418
510
|
const rows = [];
|
|
419
511
|
await this.execLock.acquire();
|
|
420
512
|
try {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ExperimentalFeature = 'views' | 'strict' | 'encryption' | 'index_method' | 'autovacuum' | 'triggers' | 'attach';
|
|
1
|
+
export type ExperimentalFeature = 'views' | 'strict' | 'encryption' | 'index_method' | 'autovacuum' | 'vacuum' | 'triggers' | 'attach' | 'multiprocess_wal' | 'without_rowid';
|
|
2
2
|
/** Supported encryption ciphers for local database encryption. */
|
|
3
3
|
export type EncryptionCipher = 'aes128gcm' | 'aes256gcm' | 'aegis256' | 'aegis256x2' | 'aegis128l' | 'aegis128x2' | 'aegis128x4';
|
|
4
4
|
/** Encryption configuration for local encryption. */
|
|
@@ -11,12 +11,18 @@ export interface DatabaseOpts {
|
|
|
11
11
|
readonly?: boolean;
|
|
12
12
|
fileMustExist?: boolean;
|
|
13
13
|
timeout?: number;
|
|
14
|
+
/** Default maximum query execution time in milliseconds before interruption. */
|
|
15
|
+
defaultQueryTimeout?: number;
|
|
14
16
|
tracing?: 'info' | 'debug' | 'trace';
|
|
15
17
|
/** Experimental features to enable */
|
|
16
18
|
experimental?: ExperimentalFeature[];
|
|
17
19
|
/** Optional local encryption configuration */
|
|
18
20
|
encryption?: EncryptionOpts;
|
|
19
21
|
}
|
|
22
|
+
export interface QueryOptions {
|
|
23
|
+
/** Per-query timeout in milliseconds. Overrides defaultQueryTimeout for this call. */
|
|
24
|
+
queryTimeout?: number;
|
|
25
|
+
}
|
|
20
26
|
export interface NativeDatabase {
|
|
21
27
|
memory: boolean;
|
|
22
28
|
path: string;
|
|
@@ -28,7 +34,7 @@ export interface NativeDatabase {
|
|
|
28
34
|
ioLoopSync(): any;
|
|
29
35
|
ioLoopAsync(): Promise<void>;
|
|
30
36
|
prepare(sql: string): NativeStatement;
|
|
31
|
-
executor(sql: string): NativeExecutor;
|
|
37
|
+
executor(sql: string, queryOptions?: QueryOptions): NativeExecutor;
|
|
32
38
|
defaultSafeIntegers(toggle: boolean): any;
|
|
33
39
|
totalChanges(): number;
|
|
34
40
|
changes(): number;
|
|
@@ -40,13 +46,17 @@ export declare const STEP_DONE = 2;
|
|
|
40
46
|
export declare const STEP_IO = 3;
|
|
41
47
|
export interface TableColumn {
|
|
42
48
|
name: string;
|
|
43
|
-
type: string;
|
|
49
|
+
type: string | null;
|
|
50
|
+
column: null;
|
|
51
|
+
table: null;
|
|
52
|
+
database: null;
|
|
44
53
|
}
|
|
45
54
|
export interface NativeExecutor {
|
|
46
55
|
stepSync(): number;
|
|
47
56
|
reset(): any;
|
|
48
57
|
}
|
|
49
58
|
export interface NativeStatement {
|
|
59
|
+
setQueryTimeout(queryOptions?: QueryOptions): void;
|
|
50
60
|
stepAsync(): Promise<number>;
|
|
51
61
|
stepSync(): number;
|
|
52
62
|
pluck(pluckMode: boolean): any;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,GAAG,cAAc,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,GAAG,cAAc,GAAG,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,kBAAkB,GAAG,eAAe,CAAC;AAE9K,kEAAkE;AAClE,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,CAAA;AAEhI,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,gBAAgB,CAAA;IACxB,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gFAAgF;IAChF,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;IACpC,sCAAsC;IACtC,YAAY,CAAC,EAAE,mBAAmB,EAAE,CAAA;IACpC,8CAA8C;IAC9C,UAAU,CAAC,EAAE,cAAc,CAAA;CAC9B;AAED,MAAM,WAAW,YAAY;IACzB,sFAAsF;IACtF,YAAY,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CA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