@tursodatabase/database-common 0.7.2 → 0.8.0-pre.10
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.map +1 -1
- package/dist/compat.js +13 -13
- package/dist/promise.d.ts +28 -13
- package/dist/promise.d.ts.map +1 -1
- package/dist/promise.js +230 -55
- package/dist/sqlite-error.d.ts +12 -0
- package/dist/sqlite-error.d.ts.map +1 -1
- package/dist/sqlite-error.js +12 -0
- package/dist/types.d.ts +6 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +2 -2
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,cAAc,EAAE,eAAe,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../compat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAA4C,MAAM,YAAY,CAAC;AAoDrH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,CAAC;AAE1G,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC;AAEnD,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AA+CD;;G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EAAE,EAAE,cAAc;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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { bindParams } from "./bind.js";
|
|
2
2
|
import { SqliteError } from "./sqlite-error.js";
|
|
3
|
-
import { STEP_IO, STEP_ROW, STEP_DONE } from "./types.js";
|
|
3
|
+
import { STEP_IO, STEP_ROW, STEP_DONE, STEP_SLEEP } from "./types.js";
|
|
4
4
|
const convertibleErrorTypes = { TypeError };
|
|
5
5
|
const CONVERTIBLE_ERROR_PREFIX = "[TURSO_CONVERT_TYPE]";
|
|
6
6
|
function convertError(err) {
|
|
@@ -215,8 +215,8 @@ class Database {
|
|
|
215
215
|
const exec = this.db.executor(sql, queryOptions);
|
|
216
216
|
try {
|
|
217
217
|
while (true) {
|
|
218
|
-
const stepResult = exec.stepSync();
|
|
219
|
-
if (stepResult === STEP_IO) {
|
|
218
|
+
const [stepResult] = exec.stepSync();
|
|
219
|
+
if (stepResult === STEP_IO || stepResult === STEP_SLEEP) {
|
|
220
220
|
this.db.ioLoopSync();
|
|
221
221
|
continue;
|
|
222
222
|
}
|
|
@@ -265,8 +265,8 @@ class Database {
|
|
|
265
265
|
const rows = [];
|
|
266
266
|
try {
|
|
267
267
|
while (true) {
|
|
268
|
-
const stepResult = stmt.stepSync();
|
|
269
|
-
if (stepResult === STEP_IO) {
|
|
268
|
+
const [stepResult] = stmt.stepSync();
|
|
269
|
+
if (stepResult === STEP_IO || stepResult === STEP_SLEEP) {
|
|
270
270
|
this.db.ioLoopSync();
|
|
271
271
|
continue;
|
|
272
272
|
}
|
|
@@ -392,8 +392,8 @@ class Statement {
|
|
|
392
392
|
this.stmt.setQueryTimeout(queryOptions);
|
|
393
393
|
bindParams(this.stmt, toBindArgs(params));
|
|
394
394
|
for (;;) {
|
|
395
|
-
const stepResult = this.stmt.stepSync();
|
|
396
|
-
if (stepResult === STEP_IO) {
|
|
395
|
+
const [stepResult] = this.stmt.stepSync();
|
|
396
|
+
if (stepResult === STEP_IO || stepResult === STEP_SLEEP) {
|
|
397
397
|
this.db.ioLoopSync();
|
|
398
398
|
continue;
|
|
399
399
|
}
|
|
@@ -421,8 +421,8 @@ class Statement {
|
|
|
421
421
|
bindParams(this.stmt, toBindArgs(params));
|
|
422
422
|
let row = undefined;
|
|
423
423
|
for (;;) {
|
|
424
|
-
const stepResult = this.stmt.stepSync();
|
|
425
|
-
if (stepResult === STEP_IO) {
|
|
424
|
+
const [stepResult] = this.stmt.stepSync();
|
|
425
|
+
if (stepResult === STEP_IO || stepResult === STEP_SLEEP) {
|
|
426
426
|
this.db.ioLoopSync();
|
|
427
427
|
continue;
|
|
428
428
|
}
|
|
@@ -446,8 +446,8 @@ class Statement {
|
|
|
446
446
|
this.stmt.setQueryTimeout(queryOptions);
|
|
447
447
|
bindParams(this.stmt, toBindArgs(params));
|
|
448
448
|
while (true) {
|
|
449
|
-
const stepResult = this.stmt.stepSync();
|
|
450
|
-
if (stepResult === STEP_IO) {
|
|
449
|
+
const [stepResult] = this.stmt.stepSync();
|
|
450
|
+
if (stepResult === STEP_IO || stepResult === STEP_SLEEP) {
|
|
451
451
|
this.db.ioLoopSync();
|
|
452
452
|
continue;
|
|
453
453
|
}
|
|
@@ -471,8 +471,8 @@ class Statement {
|
|
|
471
471
|
bindParams(this.stmt, toBindArgs(params));
|
|
472
472
|
const rows = [];
|
|
473
473
|
for (;;) {
|
|
474
|
-
const stepResult = this.stmt.stepSync();
|
|
475
|
-
if (stepResult === STEP_IO) {
|
|
474
|
+
const [stepResult] = this.stmt.stepSync();
|
|
475
|
+
if (stepResult === STEP_IO || stepResult === STEP_SLEEP) {
|
|
476
476
|
this.db.ioLoopSync();
|
|
477
477
|
continue;
|
|
478
478
|
}
|
package/dist/promise.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export interface BatchOptions {
|
|
|
8
8
|
mode?: BatchMode;
|
|
9
9
|
raw?: boolean;
|
|
10
10
|
}
|
|
11
|
+
type BatchStatement = string | {
|
|
12
|
+
sql: string;
|
|
13
|
+
args?: any[] | Record<string, any>;
|
|
14
|
+
};
|
|
11
15
|
export type BatchRow = Record<string, any> | any[];
|
|
12
16
|
/**
|
|
13
17
|
* The result of executing a single statement within `batch()`, matching the
|
|
@@ -22,6 +26,20 @@ export interface ResultSet {
|
|
|
22
26
|
rows: Array<BatchRow>;
|
|
23
27
|
/** Number of rows changed by the statement (0 for SELECT). */
|
|
24
28
|
rowsAffected: number;
|
|
29
|
+
/** Rowid inserted by the statement, when the statement inserted one. */
|
|
30
|
+
lastInsertRowid?: number;
|
|
31
|
+
/** Rows read while executing the statement. The embedded engine does
|
|
32
|
+
* not report this per statement; the serverless driver reports the
|
|
33
|
+
* server's value. */
|
|
34
|
+
rowsRead?: number;
|
|
35
|
+
/** Rows written while executing the statement. The embedded engine
|
|
36
|
+
* does not report this per statement; the serverless driver reports
|
|
37
|
+
* the server's value. */
|
|
38
|
+
rowsWritten?: number;
|
|
39
|
+
/** Server-side execution time in milliseconds. The embedded engine
|
|
40
|
+
* does not report this per statement; the serverless driver reports
|
|
41
|
+
* the server's value. */
|
|
42
|
+
queryDurationMs?: number;
|
|
25
43
|
}
|
|
26
44
|
/**
|
|
27
45
|
* Rejects transaction callbacks that cannot be using the `Transaction`
|
|
@@ -157,10 +175,8 @@ declare class Database {
|
|
|
157
175
|
* When `mode` is set, `batch()` owns the surrounding
|
|
158
176
|
* `BEGIN`/`COMMIT`/`ROLLBACK`, so the `statements` array must not
|
|
159
177
|
* contain its own transaction-control SQL (`BEGIN`, `COMMIT`,
|
|
160
|
-
* `ROLLBACK`, `SAVEPOINT`, `RELEASE`).
|
|
161
|
-
*
|
|
162
|
-
* transaction mid-batch and leave earlier statements committed,
|
|
163
|
-
* defeating the all-or-nothing contract.
|
|
178
|
+
* `END`, `ROLLBACK`, `SAVEPOINT`, `RELEASE`). Such input is rejected
|
|
179
|
+
* before the batch starts.
|
|
164
180
|
*
|
|
165
181
|
* @param statements - An array of SQL strings or `{ sql, args }` objects.
|
|
166
182
|
* @param mode - When set, wraps the batch in `BEGIN <mode>` / `COMMIT`
|
|
@@ -168,7 +184,12 @@ declare class Database {
|
|
|
168
184
|
* transaction.
|
|
169
185
|
* @returns An array of `ResultSet`s — one per input statement, in order —
|
|
170
186
|
* matching the libsql-js batch contract. Each `ResultSet` carries that
|
|
171
|
-
* statement's `columns`, `columnTypes`, `rows`,
|
|
187
|
+
* statement's `columns`, `columnTypes`, `rows`, `rowsAffected`, and
|
|
188
|
+
* `lastInsertRowid`. Execution stops at the first statement that
|
|
189
|
+
* fails: the thrown error carries `batchIndex` (the zero-based index
|
|
190
|
+
* of the failing statement) and `batchResults` (one entry per
|
|
191
|
+
* statement — the completed statement's `ResultSet`, or `null` for
|
|
192
|
+
* the failing statement and the statements that did not run).
|
|
172
193
|
*
|
|
173
194
|
* @example
|
|
174
195
|
* // Plain SQL strings (non-atomic).
|
|
@@ -199,10 +220,7 @@ declare class Database {
|
|
|
199
220
|
* });
|
|
200
221
|
* await txn.immediate();
|
|
201
222
|
*/
|
|
202
|
-
batch(statements:
|
|
203
|
-
sql: string;
|
|
204
|
-
args?: any[] | Record<string, any>;
|
|
205
|
-
}>, options?: BatchMode | BatchOptions): Promise<ResultSet[]>;
|
|
223
|
+
batch(statements: BatchStatement[], options?: BatchMode | BatchOptions): Promise<ResultSet[]>;
|
|
206
224
|
/**
|
|
207
225
|
* Prepares the SQL and executes it as `Statement.run`, returning the run info.
|
|
208
226
|
*
|
|
@@ -339,10 +357,7 @@ declare class Transaction {
|
|
|
339
357
|
*
|
|
340
358
|
* @param statements - An array of SQL strings or `{ sql, args }` objects.
|
|
341
359
|
*/
|
|
342
|
-
batch(statements:
|
|
343
|
-
sql: string;
|
|
344
|
-
args?: any[] | Record<string, any>;
|
|
345
|
-
}>, options?: BatchMode | BatchOptions): Promise<ResultSet[]>;
|
|
360
|
+
batch(statements: BatchStatement[], options?: BatchMode | BatchOptions): Promise<ResultSet[]>;
|
|
346
361
|
}
|
|
347
362
|
interface MaybeLazy<T> {
|
|
348
363
|
apply(fn: (value: T) => void): any;
|
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,EAAE,YAAY,
|
|
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,EAA0D,MAAM,YAAY,CAAC;AA6DnI;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,CAAC;AAE1G,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,S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AEpB;IAED,IAAI,QAAQ,mBAEX;IAED;;OAEG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;;;;IAuC3B;;;;OAIG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;IAmC3B;;;;OAIG;IACI,OAAO,CAAC,GAAG,cAAc,OAAA;IAgChC;;;;OAIG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;IAmCrB,EAAE;IAIR;;OAEG;IACH,SAAS;IAKT;;;;;OAKG;IACH,IAAI,CAAC,GAAG,cAAc,OAAA;IAStB,KAAK;CAUN;AAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,yBAAyB,EAAE,YAAY,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/promise.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncLock } from "./async-lock.js";
|
|
2
2
|
import { bindParams } from "./bind.js";
|
|
3
3
|
import { SqliteError } from "./sqlite-error.js";
|
|
4
|
-
import { STEP_IO, STEP_ROW, STEP_DONE } from "./types.js";
|
|
4
|
+
import { STEP_IO, STEP_ROW, STEP_DONE, STEP_SLEEP } from "./types.js";
|
|
5
5
|
const convertibleErrorTypes = { TypeError };
|
|
6
6
|
const CONVERTIBLE_ERROR_PREFIX = "[TURSO_CONVERT_TYPE]";
|
|
7
7
|
function convertError(err) {
|
|
@@ -17,6 +17,14 @@ function createErrorByName(name, message) {
|
|
|
17
17
|
}
|
|
18
18
|
return new ErrorConstructor(message);
|
|
19
19
|
}
|
|
20
|
+
// The engine returned STEP_SLEEP: it wants the statement stepped again after a
|
|
21
|
+
// delay (busy-handler backoff, or a yield with no pending I/O). Park the step
|
|
22
|
+
// loop on a timer promise — unlike STEP_IO
|
|
23
|
+
// there is no I/O completion coming to wake us up, so waiting on the IO
|
|
24
|
+
// notifier would hang (WASM) or spin (native).
|
|
25
|
+
function sleepBeforeRetry(ms) {
|
|
26
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
27
|
+
}
|
|
20
28
|
function isQueryOptions(value) {
|
|
21
29
|
return value != null
|
|
22
30
|
&& typeof value === "object"
|
|
@@ -41,6 +49,14 @@ function toBindArgs(params) {
|
|
|
41
49
|
}
|
|
42
50
|
return [params];
|
|
43
51
|
}
|
|
52
|
+
const TRANSACTION_CONTROL_KEYWORDS = new Set([
|
|
53
|
+
"BEGIN",
|
|
54
|
+
"COMMIT",
|
|
55
|
+
"END",
|
|
56
|
+
"ROLLBACK",
|
|
57
|
+
"SAVEPOINT",
|
|
58
|
+
"RELEASE",
|
|
59
|
+
]);
|
|
44
60
|
function normalizeBatchMode(mode) {
|
|
45
61
|
switch (String(mode).toLowerCase()) {
|
|
46
62
|
case "write":
|
|
@@ -70,16 +86,65 @@ function normalizeBatchOptions(options) {
|
|
|
70
86
|
raw: false,
|
|
71
87
|
};
|
|
72
88
|
}
|
|
89
|
+
function firstSqlKeyword(sql) {
|
|
90
|
+
let offset = 0;
|
|
91
|
+
while (offset < sql.length) {
|
|
92
|
+
if (/\s/.test(sql[offset]) || sql[offset] === ";") {
|
|
93
|
+
offset++;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (sql.startsWith("--", offset)) {
|
|
97
|
+
const newline = sql.indexOf("\n", offset + 2);
|
|
98
|
+
if (newline < 0)
|
|
99
|
+
return undefined;
|
|
100
|
+
offset = newline + 1;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (sql.startsWith("/*", offset)) {
|
|
104
|
+
const end = sql.indexOf("*/", offset + 2);
|
|
105
|
+
if (end < 0)
|
|
106
|
+
return undefined;
|
|
107
|
+
offset = end + 2;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
return /^[A-Za-z]+/.exec(sql.slice(offset))?.[0].toUpperCase();
|
|
113
|
+
}
|
|
114
|
+
function batchInputError(index, cause) {
|
|
115
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
116
|
+
const error = new TypeError(`batch statement ${index} failed: ${message}`);
|
|
117
|
+
error.batchIndex = index;
|
|
118
|
+
error.batchResults = [];
|
|
119
|
+
return error;
|
|
120
|
+
}
|
|
121
|
+
function attachRollbackError(primary, rollback) {
|
|
122
|
+
const rollbackError = rollback instanceof Error ? rollback : new Error(String(rollback));
|
|
123
|
+
if (primary instanceof Error) {
|
|
124
|
+
primary.rollbackError = rollbackError;
|
|
125
|
+
return primary;
|
|
126
|
+
}
|
|
127
|
+
const error = new Error(String(primary));
|
|
128
|
+
error.cause = primary;
|
|
129
|
+
error.rollbackError = rollbackError;
|
|
130
|
+
return error;
|
|
131
|
+
}
|
|
73
132
|
/**
|
|
74
133
|
* Builds a libSQL-style `ResultSet` for a single statement in a `batch()`.
|
|
75
134
|
*/
|
|
76
|
-
function makeResultSet(columns, columnTypes, rows, rowsAffected) {
|
|
77
|
-
|
|
135
|
+
function makeResultSet(columns, columnTypes, rows, rowsAffected, lastInsertRowid) {
|
|
136
|
+
const resultSet = {
|
|
78
137
|
columns,
|
|
79
138
|
columnTypes,
|
|
80
139
|
rows,
|
|
81
140
|
rowsAffected,
|
|
82
141
|
};
|
|
142
|
+
// Only statements that inserted carry the key, so callers can use
|
|
143
|
+
// `"lastInsertRowid" in resultSet` to detect an insert.
|
|
144
|
+
if (lastInsertRowid !== undefined) {
|
|
145
|
+
resultSet.lastInsertRowid = lastInsertRowid;
|
|
146
|
+
}
|
|
147
|
+
return resultSet;
|
|
83
148
|
}
|
|
84
149
|
/**
|
|
85
150
|
* Rejects transaction callbacks that cannot be using the `Transaction`
|
|
@@ -292,10 +357,8 @@ class Database {
|
|
|
292
357
|
* When `mode` is set, `batch()` owns the surrounding
|
|
293
358
|
* `BEGIN`/`COMMIT`/`ROLLBACK`, so the `statements` array must not
|
|
294
359
|
* contain its own transaction-control SQL (`BEGIN`, `COMMIT`,
|
|
295
|
-
* `ROLLBACK`, `SAVEPOINT`, `RELEASE`).
|
|
296
|
-
*
|
|
297
|
-
* transaction mid-batch and leave earlier statements committed,
|
|
298
|
-
* defeating the all-or-nothing contract.
|
|
360
|
+
* `END`, `ROLLBACK`, `SAVEPOINT`, `RELEASE`). Such input is rejected
|
|
361
|
+
* before the batch starts.
|
|
299
362
|
*
|
|
300
363
|
* @param statements - An array of SQL strings or `{ sql, args }` objects.
|
|
301
364
|
* @param mode - When set, wraps the batch in `BEGIN <mode>` / `COMMIT`
|
|
@@ -303,7 +366,12 @@ class Database {
|
|
|
303
366
|
* transaction.
|
|
304
367
|
* @returns An array of `ResultSet`s — one per input statement, in order —
|
|
305
368
|
* matching the libsql-js batch contract. Each `ResultSet` carries that
|
|
306
|
-
* statement's `columns`, `columnTypes`, `rows`,
|
|
369
|
+
* statement's `columns`, `columnTypes`, `rows`, `rowsAffected`, and
|
|
370
|
+
* `lastInsertRowid`. Execution stops at the first statement that
|
|
371
|
+
* fails: the thrown error carries `batchIndex` (the zero-based index
|
|
372
|
+
* of the failing statement) and `batchResults` (one entry per
|
|
373
|
+
* statement — the completed statement's `ResultSet`, or `null` for
|
|
374
|
+
* the failing statement and the statements that did not run).
|
|
307
375
|
*
|
|
308
376
|
* @example
|
|
309
377
|
* // Plain SQL strings (non-atomic).
|
|
@@ -467,11 +535,15 @@ class Database {
|
|
|
467
535
|
const exec = this.db.executor(sql, queryOptions);
|
|
468
536
|
try {
|
|
469
537
|
while (true) {
|
|
470
|
-
const stepResult = exec.stepSync();
|
|
538
|
+
const [stepResult, sleepMs] = exec.stepSync();
|
|
471
539
|
if (stepResult === STEP_IO) {
|
|
472
540
|
await this.io();
|
|
473
541
|
continue;
|
|
474
542
|
}
|
|
543
|
+
if (stepResult === STEP_SLEEP) {
|
|
544
|
+
await sleepBeforeRetry(sleepMs);
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
475
547
|
if (stepResult === STEP_DONE) {
|
|
476
548
|
break;
|
|
477
549
|
}
|
|
@@ -524,11 +596,15 @@ async function executeBatch(native, io, statements, options) {
|
|
|
524
596
|
const exec = native.executor(sql);
|
|
525
597
|
try {
|
|
526
598
|
while (true) {
|
|
527
|
-
const stepResult = exec.stepSync();
|
|
599
|
+
const [stepResult, sleepMs] = exec.stepSync();
|
|
528
600
|
if (stepResult === STEP_IO) {
|
|
529
601
|
await io();
|
|
530
602
|
continue;
|
|
531
603
|
}
|
|
604
|
+
if (stepResult === STEP_SLEEP) {
|
|
605
|
+
await sleepBeforeRetry(sleepMs);
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
532
608
|
if (stepResult === STEP_DONE) {
|
|
533
609
|
break;
|
|
534
610
|
}
|
|
@@ -540,56 +616,109 @@ async function executeBatch(native, io, statements, options) {
|
|
|
540
616
|
};
|
|
541
617
|
const { mode, raw } = normalizeBatchOptions(options);
|
|
542
618
|
const wrap = mode != null && !native.inTransaction();
|
|
619
|
+
const normalizedStatements = statements.map((statement, index) => {
|
|
620
|
+
if (typeof statement === "string" || statement.args === undefined) {
|
|
621
|
+
return statement;
|
|
622
|
+
}
|
|
623
|
+
try {
|
|
624
|
+
const args = Array.isArray(statement.args)
|
|
625
|
+
? statement.args.map(normalizeBatchBindValue)
|
|
626
|
+
: Object.fromEntries(Object.entries(statement.args).map(([name, value]) => [name, normalizeBatchBindValue(value)]));
|
|
627
|
+
return { sql: statement.sql, args };
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
throw batchInputError(index, error);
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
if (wrap) {
|
|
634
|
+
for (let index = 0; index < normalizedStatements.length; index++) {
|
|
635
|
+
const statement = normalizedStatements[index];
|
|
636
|
+
const sql = typeof statement === "string" ? statement : statement.sql;
|
|
637
|
+
const keyword = firstSqlKeyword(sql);
|
|
638
|
+
if (keyword !== undefined && TRANSACTION_CONTROL_KEYWORDS.has(keyword)) {
|
|
639
|
+
throw batchInputError(index, new Error(`${keyword} is not allowed in an atomic batch`));
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
543
643
|
if (wrap) {
|
|
544
644
|
await runRawSql(`BEGIN ${normalizeBatchMode(mode)}`);
|
|
545
645
|
}
|
|
546
646
|
const results = [];
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
647
|
+
const executeStatement = async (statement) => {
|
|
648
|
+
const sql = typeof statement === "string" ? statement : statement.sql;
|
|
649
|
+
const args = typeof statement === "string" ? undefined : statement.args;
|
|
650
|
+
let nativeStmt;
|
|
651
|
+
try {
|
|
652
|
+
nativeStmt = native.prepare(sql);
|
|
653
|
+
}
|
|
654
|
+
catch (err) {
|
|
655
|
+
throw convertError(err);
|
|
656
|
+
}
|
|
657
|
+
try {
|
|
658
|
+
if (args !== undefined) {
|
|
659
|
+
bindParams(nativeStmt, [args]);
|
|
554
660
|
}
|
|
555
|
-
|
|
556
|
-
|
|
661
|
+
const cols = nativeStmt.columns();
|
|
662
|
+
const columnNames = cols.map((c) => c.name);
|
|
663
|
+
const columnTypes = cols.map((c) => c.type ?? "");
|
|
664
|
+
if (columnNames.length > 0) {
|
|
665
|
+
nativeStmt.raw(raw);
|
|
557
666
|
}
|
|
667
|
+
const totalChangesBefore = native.totalChanges();
|
|
668
|
+
const rowidBefore = native.lastInsertRowid();
|
|
669
|
+
const rows = [];
|
|
558
670
|
try {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const columnTypes = cols.map((c) => c.type ?? "");
|
|
565
|
-
if (columnNames.length > 0) {
|
|
566
|
-
nativeStmt.raw(raw);
|
|
567
|
-
}
|
|
568
|
-
const totalChangesBefore = native.totalChanges();
|
|
569
|
-
const rows = [];
|
|
570
|
-
try {
|
|
571
|
-
while (true) {
|
|
572
|
-
const stepResult = await nativeStmt.stepSync();
|
|
573
|
-
if (stepResult === STEP_IO) {
|
|
574
|
-
await io();
|
|
575
|
-
continue;
|
|
576
|
-
}
|
|
577
|
-
if (stepResult === STEP_DONE) {
|
|
578
|
-
break;
|
|
579
|
-
}
|
|
580
|
-
rows.push(nativeStmt.row());
|
|
671
|
+
while (true) {
|
|
672
|
+
const [stepResult, sleepMs] = await nativeStmt.stepSync();
|
|
673
|
+
if (stepResult === STEP_IO) {
|
|
674
|
+
await io();
|
|
675
|
+
continue;
|
|
581
676
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
677
|
+
if (stepResult === STEP_SLEEP) {
|
|
678
|
+
await sleepBeforeRetry(sleepMs);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (stepResult === STEP_DONE) {
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
rows.push(nativeStmt.row());
|
|
589
685
|
}
|
|
686
|
+
const rowsAffected = columnNames.length > 0
|
|
687
|
+
? 0
|
|
688
|
+
: native.totalChanges() !== totalChangesBefore ? native.changes() : 0;
|
|
689
|
+
// The engine tracks the inserted rowid per connection, not per
|
|
690
|
+
// statement; a change across this statement means it inserted.
|
|
691
|
+
const rowidAfter = native.lastInsertRowid();
|
|
692
|
+
const lastInsertRowid = rowidAfter !== rowidBefore ? rowidAfter : undefined;
|
|
693
|
+
return makeResultSet(columnNames, columnTypes, rows, rowsAffected, lastInsertRowid);
|
|
590
694
|
}
|
|
591
695
|
finally {
|
|
592
|
-
nativeStmt.
|
|
696
|
+
nativeStmt.reset();
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
finally {
|
|
700
|
+
nativeStmt.finalize();
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
try {
|
|
704
|
+
for (let index = 0; index < normalizedStatements.length; index++) {
|
|
705
|
+
try {
|
|
706
|
+
results.push(await executeStatement(normalizedStatements[index]));
|
|
707
|
+
}
|
|
708
|
+
catch (err) {
|
|
709
|
+
// Identify the failing statement and carry the results of the
|
|
710
|
+
// statements that completed, matching the serverless driver:
|
|
711
|
+
// one entry per statement, null for the failing statement and
|
|
712
|
+
// the ones that never ran.
|
|
713
|
+
if (err instanceof Error) {
|
|
714
|
+
const batchErr = err;
|
|
715
|
+
batchErr.batchIndex = index;
|
|
716
|
+
batchErr.batchResults = [
|
|
717
|
+
...results.map((result) => result),
|
|
718
|
+
...Array(normalizedStatements.length - results.length).fill(null),
|
|
719
|
+
];
|
|
720
|
+
}
|
|
721
|
+
throw err;
|
|
593
722
|
}
|
|
594
723
|
}
|
|
595
724
|
if (wrap) {
|
|
@@ -601,12 +730,38 @@ async function executeBatch(native, io, statements, options) {
|
|
|
601
730
|
try {
|
|
602
731
|
await runRawSql("ROLLBACK");
|
|
603
732
|
}
|
|
604
|
-
catch {
|
|
733
|
+
catch (rollbackError) {
|
|
734
|
+
throw attachRollbackError(err, rollbackError);
|
|
735
|
+
}
|
|
605
736
|
}
|
|
606
737
|
throw err;
|
|
607
738
|
}
|
|
608
739
|
return results;
|
|
609
740
|
}
|
|
741
|
+
function normalizeBatchBindValue(value) {
|
|
742
|
+
if (value === null || value === undefined)
|
|
743
|
+
return null;
|
|
744
|
+
if (typeof value === "number") {
|
|
745
|
+
if (!Number.isFinite(value)) {
|
|
746
|
+
throw new TypeError("Only finite numbers (not Infinity or NaN) can be passed as arguments");
|
|
747
|
+
}
|
|
748
|
+
return value;
|
|
749
|
+
}
|
|
750
|
+
if (typeof value === "bigint") {
|
|
751
|
+
if (value < -(1n << 63n) || value > (1n << 63n) - 1n) {
|
|
752
|
+
throw new TypeError("BigInt value is outside SQLite's signed 64-bit integer range");
|
|
753
|
+
}
|
|
754
|
+
return value;
|
|
755
|
+
}
|
|
756
|
+
if (typeof value === "boolean" ||
|
|
757
|
+
typeof value === "string" ||
|
|
758
|
+
(ArrayBuffer.isView(value) && !(value instanceof DataView))) {
|
|
759
|
+
return value;
|
|
760
|
+
}
|
|
761
|
+
if (value instanceof ArrayBuffer)
|
|
762
|
+
return new Uint8Array(value);
|
|
763
|
+
return String(value);
|
|
764
|
+
}
|
|
610
765
|
/**
|
|
611
766
|
* A handle to an open transaction, passed as the first argument to the
|
|
612
767
|
* callback of `Database.transactionAsync()`. All SQL of the transaction
|
|
@@ -663,11 +818,15 @@ class Transaction {
|
|
|
663
818
|
const exec = this.db.executor(sql, queryOptions);
|
|
664
819
|
try {
|
|
665
820
|
while (true) {
|
|
666
|
-
const stepResult = exec.stepSync();
|
|
821
|
+
const [stepResult, sleepMs] = exec.stepSync();
|
|
667
822
|
if (stepResult === STEP_IO) {
|
|
668
823
|
await this.ioStep();
|
|
669
824
|
continue;
|
|
670
825
|
}
|
|
826
|
+
if (stepResult === STEP_SLEEP) {
|
|
827
|
+
await sleepBeforeRetry(sleepMs);
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
671
830
|
if (stepResult === STEP_DONE) {
|
|
672
831
|
break;
|
|
673
832
|
}
|
|
@@ -894,11 +1053,15 @@ class Statement {
|
|
|
894
1053
|
await this.execLock.acquire();
|
|
895
1054
|
try {
|
|
896
1055
|
while (true) {
|
|
897
|
-
const stepResult = await stmt.stepSync();
|
|
1056
|
+
const [stepResult, sleepMs] = await stmt.stepSync();
|
|
898
1057
|
if (stepResult === STEP_IO) {
|
|
899
1058
|
await this.io();
|
|
900
1059
|
continue;
|
|
901
1060
|
}
|
|
1061
|
+
if (stepResult === STEP_SLEEP) {
|
|
1062
|
+
await sleepBeforeRetry(sleepMs);
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
902
1065
|
if (stepResult === STEP_DONE) {
|
|
903
1066
|
break;
|
|
904
1067
|
}
|
|
@@ -930,11 +1093,15 @@ class Statement {
|
|
|
930
1093
|
let row = undefined;
|
|
931
1094
|
try {
|
|
932
1095
|
while (true) {
|
|
933
|
-
const stepResult = await stmt.stepSync();
|
|
1096
|
+
const [stepResult, sleepMs] = await stmt.stepSync();
|
|
934
1097
|
if (stepResult === STEP_IO) {
|
|
935
1098
|
await this.io();
|
|
936
1099
|
continue;
|
|
937
1100
|
}
|
|
1101
|
+
if (stepResult === STEP_SLEEP) {
|
|
1102
|
+
await sleepBeforeRetry(sleepMs);
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
938
1105
|
if (stepResult === STEP_DONE) {
|
|
939
1106
|
break;
|
|
940
1107
|
}
|
|
@@ -963,11 +1130,15 @@ class Statement {
|
|
|
963
1130
|
await this.execLock.acquire();
|
|
964
1131
|
try {
|
|
965
1132
|
while (true) {
|
|
966
|
-
const stepResult = await stmt.stepSync();
|
|
1133
|
+
const [stepResult, sleepMs] = await stmt.stepSync();
|
|
967
1134
|
if (stepResult === STEP_IO) {
|
|
968
1135
|
await this.io();
|
|
969
1136
|
continue;
|
|
970
1137
|
}
|
|
1138
|
+
if (stepResult === STEP_SLEEP) {
|
|
1139
|
+
await sleepBeforeRetry(sleepMs);
|
|
1140
|
+
continue;
|
|
1141
|
+
}
|
|
971
1142
|
if (stepResult === STEP_DONE) {
|
|
972
1143
|
break;
|
|
973
1144
|
}
|
|
@@ -995,11 +1166,15 @@ class Statement {
|
|
|
995
1166
|
await this.execLock.acquire();
|
|
996
1167
|
try {
|
|
997
1168
|
while (true) {
|
|
998
|
-
const stepResult = await stmt.stepSync();
|
|
1169
|
+
const [stepResult, sleepMs] = await stmt.stepSync();
|
|
999
1170
|
if (stepResult === STEP_IO) {
|
|
1000
1171
|
await this.io();
|
|
1001
1172
|
continue;
|
|
1002
1173
|
}
|
|
1174
|
+
if (stepResult === STEP_SLEEP) {
|
|
1175
|
+
await sleepBeforeRetry(sleepMs);
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1003
1178
|
if (stepResult === STEP_DONE) {
|
|
1004
1179
|
break;
|
|
1005
1180
|
}
|
package/dist/sqlite-error.d.ts
CHANGED
|
@@ -2,6 +2,18 @@ export declare class SqliteError extends Error {
|
|
|
2
2
|
name: string;
|
|
3
3
|
code: string;
|
|
4
4
|
rawCode: string;
|
|
5
|
+
/** For errors raised by `batch()`: the zero-based index of the failing
|
|
6
|
+
* statement. */
|
|
7
|
+
batchIndex?: number;
|
|
8
|
+
/** For errors raised by `batch()`: one entry per input statement, in
|
|
9
|
+
* order — the completed statement's `ResultSet`, or `null` for the
|
|
10
|
+
* failing statement and the statements that did not run. In a
|
|
11
|
+
* non-atomic batch the completed statements' effects are committed; in
|
|
12
|
+
* an atomic batch they were rolled back unless `rollbackError` is set.
|
|
13
|
+
* Empty when the batch failed client-side before anything was sent. */
|
|
14
|
+
batchResults?: Array<any | null>;
|
|
15
|
+
/** A rollback error that occurred while handling this error. */
|
|
16
|
+
rollbackError?: Error;
|
|
5
17
|
constructor(message: any, code: any, rawCode: any);
|
|
6
18
|
}
|
|
7
19
|
//# sourceMappingURL=sqlite-error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-error.d.ts","sourceRoot":"","sources":["../sqlite-error.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite-error.d.ts","sourceRoot":"","sources":["../sqlite-error.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB;oBACgB;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;2EAKuE;IACvE,YAAY,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;IACjC,gEAAgE;IAChE,aAAa,CAAC,EAAE,KAAK,CAAC;gBACV,OAAO,KAAA,EAAE,IAAI,KAAA,EAAE,OAAO,KAAA;CAQnC"}
|
package/dist/sqlite-error.js
CHANGED
|
@@ -2,6 +2,18 @@ export class SqliteError extends Error {
|
|
|
2
2
|
name;
|
|
3
3
|
code;
|
|
4
4
|
rawCode;
|
|
5
|
+
/** For errors raised by `batch()`: the zero-based index of the failing
|
|
6
|
+
* statement. */
|
|
7
|
+
batchIndex;
|
|
8
|
+
/** For errors raised by `batch()`: one entry per input statement, in
|
|
9
|
+
* order — the completed statement's `ResultSet`, or `null` for the
|
|
10
|
+
* failing statement and the statements that did not run. In a
|
|
11
|
+
* non-atomic batch the completed statements' effects are committed; in
|
|
12
|
+
* an atomic batch they were rolled back unless `rollbackError` is set.
|
|
13
|
+
* Empty when the batch failed client-side before anything was sent. */
|
|
14
|
+
batchResults;
|
|
15
|
+
/** A rollback error that occurred while handling this error. */
|
|
16
|
+
rollbackError;
|
|
5
17
|
constructor(message, code, rawCode) {
|
|
6
18
|
super(message);
|
|
7
19
|
this.name = 'SqliteError';
|
package/dist/types.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export interface NativeDatabase {
|
|
|
45
45
|
export declare const STEP_ROW = 1;
|
|
46
46
|
export declare const STEP_DONE = 2;
|
|
47
47
|
export declare const STEP_IO = 3;
|
|
48
|
+
export declare const STEP_SLEEP = 4;
|
|
48
49
|
export interface TableColumn {
|
|
49
50
|
name: string;
|
|
50
51
|
type: string | null;
|
|
@@ -52,14 +53,16 @@ export interface TableColumn {
|
|
|
52
53
|
table: null;
|
|
53
54
|
database: null;
|
|
54
55
|
}
|
|
56
|
+
/** [step constant, milliseconds to wait before stepping again (nonzero only for STEP_SLEEP)] */
|
|
57
|
+
export type StepResult = [number, number];
|
|
55
58
|
export interface NativeExecutor {
|
|
56
|
-
stepSync():
|
|
59
|
+
stepSync(): StepResult;
|
|
57
60
|
reset(): any;
|
|
58
61
|
}
|
|
59
62
|
export interface NativeStatement {
|
|
60
63
|
setQueryTimeout(queryOptions?: QueryOptions): void;
|
|
61
|
-
stepAsync(): Promise<
|
|
62
|
-
stepSync():
|
|
64
|
+
stepAsync(): Promise<StepResult>;
|
|
65
|
+
stepSync(): StepResult;
|
|
63
66
|
pluck(pluckMode: boolean): any;
|
|
64
67
|
safeIntegers(toggle: boolean): any;
|
|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AC;IACZ,QAAQ,EAAE,IAAI,CAAA;CACjB;AAED,gGAAgG;AAChG,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE1C,MAAM,WAAW,cAAc;IAC3B,QAAQ,IAAI,UAAU,CAAC;IACvB,KAAK,QAAG;CACX;AACD,MAAM,WAAW,eAAe;IAC5B,eAAe,CAAC,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IACnD,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IACjC,QAAQ,IAAI,UAAU,CAAC;IAEvB,KAAK,CAAC,SAAS,EAAE,OAAO,OAAE;IAC1B,YAAY,CAAC,MAAM,EAAE,OAAO,OAAE;IAC9B,GAAG,CAAC,MAAM,EAAE,OAAO,OAAE;IACrB,OAAO,IAAI,WAAW,EAAE,CAAC;IACzB,GAAG,IAAI,GAAG,CAAC;IACX,KAAK,QAAG;IACR,QAAQ,QAAG;CACd"}
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tursodatabase/database-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-pre.10",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/tursodatabase/turso"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"typescript": "^5.9.2",
|
|
19
|
-
"vitest": "^3.2.
|
|
19
|
+
"vitest": "^3.2.7"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"tsc-build": "npm exec tsc",
|