@tursodatabase/database-common 0.2.0-pre.8 → 0.2.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/README.md +2 -2
- package/dist/compat.d.ts +12 -8
- package/dist/compat.d.ts.map +1 -1
- package/dist/compat.js +48 -54
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/promise.d.ts +27 -22
- package/dist/promise.d.ts.map +1 -1
- package/dist/promise.js +149 -95
- package/dist/promise.test.d.ts +2 -0
- package/dist/promise.test.d.ts.map +1 -0
- package/dist/promise.test.js +14 -0
- package/dist/types.d.ts +9 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This package is the Turso embedded database common JS library which is shared between final builds for Node and Browser.
|
|
4
4
|
|
|
5
|
-
Do not use this package directly - instead you must use `@tursodatabase/database` or `@tursodatabase/database-
|
|
5
|
+
Do not use this package directly - instead you must use `@tursodatabase/database` or `@tursodatabase/database-wasm`.
|
|
6
6
|
|
|
7
|
-
> **⚠️ Warning:** This software is
|
|
7
|
+
> **⚠️ Warning:** This software is in BETA. It may still contain bugs and unexpected behavior. Use caution with production data and ensure you have backups.
|
|
8
8
|
|
package/dist/compat.d.ts
CHANGED
|
@@ -3,9 +3,12 @@ import { NativeDatabase, NativeStatement } from "./types.js";
|
|
|
3
3
|
* Database represents a connection that can prepare and execute SQL statements.
|
|
4
4
|
*/
|
|
5
5
|
declare class Database {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
name: string;
|
|
7
|
+
readonly: boolean;
|
|
8
8
|
open: boolean;
|
|
9
|
+
memory: boolean;
|
|
10
|
+
inTransaction: boolean;
|
|
11
|
+
private db;
|
|
9
12
|
private _inTransaction;
|
|
10
13
|
/**
|
|
11
14
|
* Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
|
|
@@ -17,7 +20,7 @@ declare class Database {
|
|
|
17
20
|
* @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
|
|
18
21
|
* @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
|
|
19
22
|
*/
|
|
20
|
-
constructor(db: NativeDatabase
|
|
23
|
+
constructor(db: NativeDatabase);
|
|
21
24
|
/**
|
|
22
25
|
* Prepares a SQL statement for execution.
|
|
23
26
|
*
|
|
@@ -39,9 +42,10 @@ declare class Database {
|
|
|
39
42
|
loadExtension(path: any): void;
|
|
40
43
|
maxWriteReplicationIndex(): void;
|
|
41
44
|
/**
|
|
42
|
-
* Executes
|
|
45
|
+
* Executes the given SQL string
|
|
46
|
+
* Unlike prepared statements, this can execute strings that contain multiple SQL statements
|
|
43
47
|
*
|
|
44
|
-
* @param {string} sql - The SQL
|
|
48
|
+
* @param {string} sql - The string containing SQL statements to execute
|
|
45
49
|
*/
|
|
46
50
|
exec(sql: any): void;
|
|
47
51
|
/**
|
|
@@ -64,8 +68,8 @@ declare class Database {
|
|
|
64
68
|
*/
|
|
65
69
|
declare class Statement {
|
|
66
70
|
stmt: NativeStatement;
|
|
67
|
-
db:
|
|
68
|
-
constructor(stmt: NativeStatement,
|
|
71
|
+
db: NativeDatabase;
|
|
72
|
+
constructor(stmt: NativeStatement, db: NativeDatabase);
|
|
69
73
|
/**
|
|
70
74
|
* Toggle raw mode.
|
|
71
75
|
*
|
|
@@ -92,7 +96,7 @@ declare class Statement {
|
|
|
92
96
|
columns(): import("./types.js").TableColumn[];
|
|
93
97
|
get source(): void;
|
|
94
98
|
get reader(): void;
|
|
95
|
-
get database():
|
|
99
|
+
get database(): NativeDatabase;
|
|
96
100
|
/**
|
|
97
101
|
* Executes the SQL statement and returns an info object.
|
|
98
102
|
*/
|
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,EAAgC,MAAM,YAAY,CAAC;AAyB3F;;GAEG;AACH,cAAM,QAAQ;IACZ,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"compat.d.ts","sourceRoot":"","sources":["../compat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAgC,MAAM,YAAY,CAAC;AAyB3F;;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,cAAc,CAAkB;IAExC;;;;;;;;;OASG;gBACS,EAAE,EAAE,cAAc;IAa9B;;;;OAIG;IACH,OAAO,CAAC,GAAG,KAAA;IAYX;;;;OAIG;IACH,WAAW,CAAC,EAAE,KAAA;IAmCd,MAAM,CAAC,MAAM,KAAA,EAAE,OAAO,KAAA;IAoBtB,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA;IAIxB,SAAS,CAAC,OAAO,KAAA;IAIjB,QAAQ,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,EAAE,EAAE,KAAA;IAI1B,SAAS,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA;IAIvB,KAAK,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA;IAInB,aAAa,CAAC,IAAI,KAAA;IAIlB,wBAAwB;IAIxB;;;;;OAKG;IACH,IAAI,CAAC,GAAG,KAAA;IAsBR;;OAEG;IACH,SAAS;IAIT;;;;OAIG;IACH,mBAAmB,CAAC,MAAM,KAAA;IAI1B;;OAEG;IACH,KAAK;CAGN;AAED;;GAEG;AACH,cAAM,SAAS;IACb,IAAI,EAAE,eAAe,CAAC;IACtB,EAAE,EAAE,cAAc,CAAC;gBAEP,IAAI,EAAE,eAAe,EAAE,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,SAET;IAED,IAAI,QAAQ,mBAEX;IAED;;OAEG;IACH,GAAG,CAAC,GAAG,cAAc,OAAA;;;;IA0BrB;;;;OAIG;IACH,GAAG,CAAC,GAAG,cAAc,OAAA;IAkBrB;;;;OAIG;IACF,OAAO,CAAC,GAAG,cAAc,OAAA;IAmB1B;;;;OAIG;IACH,GAAG,CAAC,GAAG,cAAc,OAAA;IAoBrB;;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
|
@@ -20,9 +20,12 @@ function createErrorByName(name, message) {
|
|
|
20
20
|
* Database represents a connection that can prepare and execute SQL statements.
|
|
21
21
|
*/
|
|
22
22
|
class Database {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
name;
|
|
24
|
+
readonly;
|
|
25
25
|
open;
|
|
26
|
+
memory;
|
|
27
|
+
inTransaction;
|
|
28
|
+
db;
|
|
26
29
|
_inTransaction = false;
|
|
27
30
|
/**
|
|
28
31
|
* Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
|
|
@@ -34,32 +37,15 @@ class Database {
|
|
|
34
37
|
* @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
|
|
35
38
|
* @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
|
|
36
39
|
*/
|
|
37
|
-
constructor(db
|
|
38
|
-
opts.readonly = opts.readonly === undefined ? false : opts.readonly;
|
|
39
|
-
opts.fileMustExist =
|
|
40
|
-
opts.fileMustExist === undefined ? false : opts.fileMustExist;
|
|
41
|
-
opts.timeout = opts.timeout === undefined ? 0 : opts.timeout;
|
|
40
|
+
constructor(db) {
|
|
42
41
|
this.db = db;
|
|
43
|
-
this.
|
|
42
|
+
this.db.connectSync();
|
|
44
43
|
Object.defineProperties(this, {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return db.path;
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
readonly: {
|
|
54
|
-
get() {
|
|
55
|
-
return opts.readonly;
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
open: {
|
|
59
|
-
get() {
|
|
60
|
-
return this.db.open;
|
|
61
|
-
},
|
|
62
|
-
},
|
|
44
|
+
name: { get: () => this.db.path },
|
|
45
|
+
readonly: { get: () => this.db.readonly },
|
|
46
|
+
open: { get: () => this.db.open },
|
|
47
|
+
memory: { get: () => this.db.memory },
|
|
48
|
+
inTransaction: { get: () => this._inTransaction },
|
|
63
49
|
});
|
|
64
50
|
}
|
|
65
51
|
/**
|
|
@@ -68,14 +54,11 @@ class Database {
|
|
|
68
54
|
* @param {string} sql - The SQL statement string to prepare.
|
|
69
55
|
*/
|
|
70
56
|
prepare(sql) {
|
|
71
|
-
if (!this.open) {
|
|
72
|
-
throw new TypeError("The database connection is not open");
|
|
73
|
-
}
|
|
74
57
|
if (!sql) {
|
|
75
58
|
throw new RangeError("The supplied SQL string contains no statements");
|
|
76
59
|
}
|
|
77
60
|
try {
|
|
78
|
-
return new Statement(this.db.prepare(sql), this);
|
|
61
|
+
return new Statement(this.db.prepare(sql), this.db);
|
|
79
62
|
}
|
|
80
63
|
catch (err) {
|
|
81
64
|
throw convertError(err);
|
|
@@ -129,8 +112,13 @@ class Database {
|
|
|
129
112
|
throw new TypeError("Expected second argument to be an options object");
|
|
130
113
|
const pragma = `PRAGMA ${source}`;
|
|
131
114
|
const stmt = this.prepare(pragma);
|
|
132
|
-
|
|
133
|
-
|
|
115
|
+
try {
|
|
116
|
+
const results = stmt.all();
|
|
117
|
+
return results;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
stmt.close();
|
|
121
|
+
}
|
|
134
122
|
}
|
|
135
123
|
backup(filename, options) {
|
|
136
124
|
throw new Error("not implemented");
|
|
@@ -154,25 +142,31 @@ class Database {
|
|
|
154
142
|
throw new Error("not implemented");
|
|
155
143
|
}
|
|
156
144
|
/**
|
|
157
|
-
* Executes
|
|
145
|
+
* Executes the given SQL string
|
|
146
|
+
* Unlike prepared statements, this can execute strings that contain multiple SQL statements
|
|
158
147
|
*
|
|
159
|
-
* @param {string} sql - The SQL
|
|
148
|
+
* @param {string} sql - The string containing SQL statements to execute
|
|
160
149
|
*/
|
|
161
150
|
exec(sql) {
|
|
162
|
-
|
|
163
|
-
throw new TypeError("The database connection is not open");
|
|
164
|
-
}
|
|
151
|
+
const exec = this.db.executor(sql);
|
|
165
152
|
try {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
153
|
+
while (true) {
|
|
154
|
+
const stepResult = exec.stepSync();
|
|
155
|
+
if (stepResult === STEP_IO) {
|
|
156
|
+
this.db.ioLoopSync();
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (stepResult === STEP_DONE) {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if (stepResult === STEP_ROW) {
|
|
163
|
+
// For exec(), we don't need the row data, just continue
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
172
166
|
}
|
|
173
167
|
}
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
finally {
|
|
169
|
+
exec.reset();
|
|
176
170
|
}
|
|
177
171
|
}
|
|
178
172
|
/**
|
|
@@ -202,9 +196,9 @@ class Database {
|
|
|
202
196
|
class Statement {
|
|
203
197
|
stmt;
|
|
204
198
|
db;
|
|
205
|
-
constructor(stmt,
|
|
199
|
+
constructor(stmt, db) {
|
|
206
200
|
this.stmt = stmt;
|
|
207
|
-
this.db =
|
|
201
|
+
this.db = db;
|
|
208
202
|
}
|
|
209
203
|
/**
|
|
210
204
|
* Toggle raw mode.
|
|
@@ -254,13 +248,13 @@ class Statement {
|
|
|
254
248
|
* Executes the SQL statement and returns an info object.
|
|
255
249
|
*/
|
|
256
250
|
run(...bindParameters) {
|
|
257
|
-
const totalChangesBefore = this.db.
|
|
251
|
+
const totalChangesBefore = this.db.totalChanges();
|
|
258
252
|
this.stmt.reset();
|
|
259
253
|
bindParams(this.stmt, bindParameters);
|
|
260
254
|
for (;;) {
|
|
261
255
|
const stepResult = this.stmt.stepSync();
|
|
262
256
|
if (stepResult === STEP_IO) {
|
|
263
|
-
this.db.
|
|
257
|
+
this.db.ioLoopSync();
|
|
264
258
|
continue;
|
|
265
259
|
}
|
|
266
260
|
if (stepResult === STEP_DONE) {
|
|
@@ -271,8 +265,8 @@ class Statement {
|
|
|
271
265
|
continue;
|
|
272
266
|
}
|
|
273
267
|
}
|
|
274
|
-
const lastInsertRowid = this.db.
|
|
275
|
-
const changes = this.db.
|
|
268
|
+
const lastInsertRowid = this.db.lastInsertRowid();
|
|
269
|
+
const changes = this.db.totalChanges() === totalChangesBefore ? 0 : this.db.changes();
|
|
276
270
|
return { changes, lastInsertRowid };
|
|
277
271
|
}
|
|
278
272
|
/**
|
|
@@ -286,7 +280,7 @@ class Statement {
|
|
|
286
280
|
for (;;) {
|
|
287
281
|
const stepResult = this.stmt.stepSync();
|
|
288
282
|
if (stepResult === STEP_IO) {
|
|
289
|
-
this.db.
|
|
283
|
+
this.db.ioLoopSync();
|
|
290
284
|
continue;
|
|
291
285
|
}
|
|
292
286
|
if (stepResult === STEP_DONE) {
|
|
@@ -308,7 +302,7 @@ class Statement {
|
|
|
308
302
|
while (true) {
|
|
309
303
|
const stepResult = this.stmt.stepSync();
|
|
310
304
|
if (stepResult === STEP_IO) {
|
|
311
|
-
this.db.
|
|
305
|
+
this.db.ioLoopSync();
|
|
312
306
|
continue;
|
|
313
307
|
}
|
|
314
308
|
if (stepResult === STEP_DONE) {
|
|
@@ -331,7 +325,7 @@ class Statement {
|
|
|
331
325
|
for (;;) {
|
|
332
326
|
const stepResult = this.stmt.stepSync();
|
|
333
327
|
if (stepResult === STEP_IO) {
|
|
334
|
-
this.db.
|
|
328
|
+
this.db.ioLoopSync();
|
|
335
329
|
continue;
|
|
336
330
|
}
|
|
337
331
|
if (stepResult === STEP_DONE) {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import { Database as DatabaseCompat, Statement as StatementCompat } from "./comp
|
|
|
3
3
|
import { Database as DatabasePromise, Statement as StatementPromise } from "./promise.js";
|
|
4
4
|
import { SqliteError } from "./sqlite-error.js";
|
|
5
5
|
import { AsyncLock } from "./async-lock.js";
|
|
6
|
-
export { DatabaseCompat, StatementCompat, DatabasePromise, StatementPromise, NativeDatabase, NativeStatement, SqliteError,
|
|
6
|
+
export { DatabaseOpts, DatabaseCompat, StatementCompat, DatabasePromise, StatementPromise, NativeDatabase, NativeStatement, SqliteError, AsyncLock };
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EACH,YAAY,EACZ,cAAc,EAAE,eAAe,EAC/B,eAAe,EAAE,gBAAgB,EACjC,cAAc,EAAE,eAAe,EAC/B,WAAW,EACX,SAAS,EACZ,CAAA"}
|
package/dist/promise.d.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import { AsyncLock } from "./async-lock.js";
|
|
2
|
-
import { NativeDatabase, NativeStatement
|
|
2
|
+
import { NativeDatabase, NativeStatement } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Database represents a connection that can prepare and execute SQL statements.
|
|
5
5
|
*/
|
|
6
6
|
declare class Database {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
name: string;
|
|
8
|
+
readonly: boolean;
|
|
9
9
|
open: boolean;
|
|
10
|
-
|
|
10
|
+
memory: boolean;
|
|
11
|
+
inTransaction: boolean;
|
|
12
|
+
private db;
|
|
13
|
+
private execLock;
|
|
11
14
|
private _inTransaction;
|
|
15
|
+
protected connected: boolean;
|
|
16
|
+
constructor(db: NativeDatabase);
|
|
12
17
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @constructor
|
|
16
|
-
* @param {string} path - Path to the database file.
|
|
17
|
-
* @param {Object} opts - Options for database behavior.
|
|
18
|
-
* @param {boolean} [opts.readonly=false] - Open the database in read-only mode.
|
|
19
|
-
* @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
|
|
20
|
-
* @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
|
|
18
|
+
* connect database
|
|
21
19
|
*/
|
|
22
|
-
|
|
23
|
-
static create(): any;
|
|
24
|
-
initialize(db: NativeDatabase, name: any, readonly: any): void;
|
|
20
|
+
connect(): Promise<void>;
|
|
25
21
|
/**
|
|
26
22
|
* Prepares a SQL statement for execution.
|
|
27
23
|
*
|
|
@@ -43,9 +39,10 @@ declare class Database {
|
|
|
43
39
|
loadExtension(path: any): void;
|
|
44
40
|
maxWriteReplicationIndex(): void;
|
|
45
41
|
/**
|
|
46
|
-
* Executes
|
|
42
|
+
* Executes the given SQL string
|
|
43
|
+
* Unlike prepared statements, this can execute strings that contain multiple SQL statements
|
|
47
44
|
*
|
|
48
|
-
* @param {string} sql - The SQL
|
|
45
|
+
* @param {string} sql - The string containing SQL statements to execute
|
|
49
46
|
*/
|
|
50
47
|
exec(sql: any): Promise<void>;
|
|
51
48
|
/**
|
|
@@ -63,13 +60,21 @@ declare class Database {
|
|
|
63
60
|
*/
|
|
64
61
|
close(): Promise<void>;
|
|
65
62
|
}
|
|
63
|
+
interface MaybeLazy<T> {
|
|
64
|
+
apply(fn: (value: T) => void): any;
|
|
65
|
+
resolve(): Promise<T>;
|
|
66
|
+
must(): T;
|
|
67
|
+
}
|
|
68
|
+
declare function maybePromise<T>(arg: () => Promise<T>): MaybeLazy<T>;
|
|
69
|
+
declare function maybeValue<T>(value: T): MaybeLazy<T>;
|
|
66
70
|
/**
|
|
67
71
|
* Statement represents a prepared SQL statement that can be executed.
|
|
68
72
|
*/
|
|
69
73
|
declare class Statement {
|
|
70
|
-
stmt
|
|
71
|
-
db
|
|
72
|
-
|
|
74
|
+
private stmt;
|
|
75
|
+
private db;
|
|
76
|
+
private execLock;
|
|
77
|
+
constructor(stmt: MaybeLazy<NativeStatement>, db: NativeDatabase, execLock: AsyncLock);
|
|
73
78
|
/**
|
|
74
79
|
* Toggle raw mode.
|
|
75
80
|
*
|
|
@@ -96,7 +101,7 @@ declare class Statement {
|
|
|
96
101
|
columns(): import("./types.js").TableColumn[];
|
|
97
102
|
get source(): void;
|
|
98
103
|
get reader(): void;
|
|
99
|
-
get database():
|
|
104
|
+
get database(): NativeDatabase;
|
|
100
105
|
/**
|
|
101
106
|
* Executes the SQL statement and returns an info object.
|
|
102
107
|
*/
|
|
@@ -135,5 +140,5 @@ declare class Statement {
|
|
|
135
140
|
bind(...bindParameters: any[]): this;
|
|
136
141
|
close(): void;
|
|
137
142
|
}
|
|
138
|
-
export { Database, Statement };
|
|
143
|
+
export { Database, Statement, maybePromise, maybeValue };
|
|
139
144
|
//# sourceMappingURL=promise.d.ts.map
|
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,
|
|
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;AAyBzG;;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,QAAQ,CAAY;IAC5B,OAAO,CAAC,cAAc,CAAkB;IACxC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAS;gBAEzB,EAAE,EAAE,cAAc;IAY9B;;OAEG;IACG,OAAO;IAMb;;;;OAIG;IACH,OAAO,CAAC,GAAG,KAAA;IAgBX;;;;OAIG;IACH,WAAW,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,OAAA,KAAK,OAAO,CAAC,GAAG,CAAC;IAmClC,MAAM,CAAC,MAAM,KAAA,EAAE,OAAO,KAAA;IAoB5B,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA;IAIxB,SAAS,CAAC,OAAO,KAAA;IAIjB,QAAQ,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,EAAE,EAAE,KAAA;IAI1B,SAAS,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA;IAIvB,KAAK,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA;IAInB,aAAa,CAAC,IAAI,KAAA;IAIlB,wBAAwB;IAIxB;;;;;OAKG;IACG,IAAI,CAAC,GAAG,KAAA;IAwBd;;OAEG;IACH,SAAS;IAIT;;;;OAIG;IACH,mBAAmB,CAAC,MAAM,KAAA;IAI1B;;OAEG;IACG,KAAK;CAGZ;AAED,UAAU,SAAS,CAAC,CAAC;IACnB,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,OAAE;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,IAAI,CAAC,CAAC;CACX;AAED,iBAAS,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAgC5D;AAED,iBAAS,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAM7C;AAED;;GAEG;AACH,cAAM,SAAS;IACb,OAAO,CAAC,IAAI,CAA6B;IACzC,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,QAAQ,CAAY;gBAEhB,IAAI,EAAE,SAAS,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS;IAMrF;;;;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,SAET;IAED,IAAI,QAAQ,mBAEX;IAED;;OAEG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;;;;IAiC3B;;;;OAIG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;IA0B3B;;;;OAIG;IACI,OAAO,CAAC,GAAG,cAAc,OAAA;IA0BhC;;;;OAIG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;IA6B3B;;OAEG;IACH,SAAS;IAKT;;;;;OAKG;IACH,IAAI,CAAC,GAAG,cAAc,OAAA;IAStB,KAAK;CAUN;AAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/promise.js
CHANGED
|
@@ -21,70 +21,52 @@ function createErrorByName(name, message) {
|
|
|
21
21
|
* Database represents a connection that can prepare and execute SQL statements.
|
|
22
22
|
*/
|
|
23
23
|
class Database {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
name;
|
|
25
|
+
readonly;
|
|
26
26
|
open;
|
|
27
|
+
memory;
|
|
28
|
+
inTransaction;
|
|
29
|
+
db;
|
|
27
30
|
execLock;
|
|
28
31
|
_inTransaction = false;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
* @constructor
|
|
33
|
-
* @param {string} path - Path to the database file.
|
|
34
|
-
* @param {Object} opts - Options for database behavior.
|
|
35
|
-
* @param {boolean} [opts.readonly=false] - Open the database in read-only mode.
|
|
36
|
-
* @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
|
|
37
|
-
* @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
|
|
38
|
-
*/
|
|
39
|
-
constructor(db, opts = {}) {
|
|
40
|
-
opts.readonly = opts.readonly === undefined ? false : opts.readonly;
|
|
41
|
-
opts.fileMustExist =
|
|
42
|
-
opts.fileMustExist === undefined ? false : opts.fileMustExist;
|
|
43
|
-
opts.timeout = opts.timeout === undefined ? 0 : opts.timeout;
|
|
44
|
-
this.initialize(db, opts.name, opts.readonly);
|
|
45
|
-
}
|
|
46
|
-
static create() {
|
|
47
|
-
return Object.create(this.prototype);
|
|
48
|
-
}
|
|
49
|
-
initialize(db, name, readonly) {
|
|
32
|
+
connected = false;
|
|
33
|
+
constructor(db) {
|
|
50
34
|
this.db = db;
|
|
51
|
-
this.memory = db.memory;
|
|
52
35
|
this.execLock = new AsyncLock();
|
|
53
36
|
Object.defineProperties(this, {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return name;
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
readonly: {
|
|
63
|
-
get() {
|
|
64
|
-
return readonly;
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
open: {
|
|
68
|
-
get() {
|
|
69
|
-
return this.db.open;
|
|
70
|
-
},
|
|
71
|
-
},
|
|
37
|
+
name: { get: () => this.db.path },
|
|
38
|
+
readonly: { get: () => this.db.readonly },
|
|
39
|
+
open: { get: () => this.db.open },
|
|
40
|
+
memory: { get: () => this.db.memory },
|
|
41
|
+
inTransaction: { get: () => this._inTransaction },
|
|
72
42
|
});
|
|
73
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* connect database
|
|
46
|
+
*/
|
|
47
|
+
async connect() {
|
|
48
|
+
if (this.connected) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
await this.db.connectAsync();
|
|
52
|
+
this.connected = true;
|
|
53
|
+
}
|
|
74
54
|
/**
|
|
75
55
|
* Prepares a SQL statement for execution.
|
|
76
56
|
*
|
|
77
57
|
* @param {string} sql - The SQL statement string to prepare.
|
|
78
58
|
*/
|
|
79
59
|
prepare(sql) {
|
|
80
|
-
if (!this.open) {
|
|
81
|
-
throw new TypeError("The database connection is not open");
|
|
82
|
-
}
|
|
83
60
|
if (!sql) {
|
|
84
61
|
throw new RangeError("The supplied SQL string contains no statements");
|
|
85
62
|
}
|
|
86
63
|
try {
|
|
87
|
-
|
|
64
|
+
if (this.connected) {
|
|
65
|
+
return new Statement(maybeValue(this.db.prepare(sql)), this.db, this.execLock);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return new Statement(maybePromise(() => this.connect().then(() => this.db.prepare(sql))), this.db, this.execLock);
|
|
69
|
+
}
|
|
88
70
|
}
|
|
89
71
|
catch (err) {
|
|
90
72
|
throw convertError(err);
|
|
@@ -137,9 +119,14 @@ class Database {
|
|
|
137
119
|
if (typeof options !== "object")
|
|
138
120
|
throw new TypeError("Expected second argument to be an options object");
|
|
139
121
|
const pragma = `PRAGMA ${source}`;
|
|
140
|
-
const stmt =
|
|
141
|
-
|
|
142
|
-
|
|
122
|
+
const stmt = this.prepare(pragma);
|
|
123
|
+
try {
|
|
124
|
+
const results = await stmt.all();
|
|
125
|
+
return results;
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
await stmt.close();
|
|
129
|
+
}
|
|
143
130
|
}
|
|
144
131
|
backup(filename, options) {
|
|
145
132
|
throw new Error("not implemented");
|
|
@@ -163,20 +150,33 @@ class Database {
|
|
|
163
150
|
throw new Error("not implemented");
|
|
164
151
|
}
|
|
165
152
|
/**
|
|
166
|
-
* Executes
|
|
153
|
+
* Executes the given SQL string
|
|
154
|
+
* Unlike prepared statements, this can execute strings that contain multiple SQL statements
|
|
167
155
|
*
|
|
168
|
-
* @param {string} sql - The SQL
|
|
156
|
+
* @param {string} sql - The string containing SQL statements to execute
|
|
169
157
|
*/
|
|
170
158
|
async exec(sql) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
const stmt = this.prepare(sql);
|
|
159
|
+
await this.execLock.acquire();
|
|
160
|
+
const exec = this.db.executor(sql);
|
|
175
161
|
try {
|
|
176
|
-
|
|
162
|
+
while (true) {
|
|
163
|
+
const stepResult = exec.stepSync();
|
|
164
|
+
if (stepResult === STEP_IO) {
|
|
165
|
+
await this.db.ioLoopAsync();
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (stepResult === STEP_DONE) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
if (stepResult === STEP_ROW) {
|
|
172
|
+
// For exec(), we don't need the row data, just continue
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
177
176
|
}
|
|
178
177
|
finally {
|
|
179
|
-
|
|
178
|
+
exec.reset();
|
|
179
|
+
this.execLock.release();
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
@@ -200,15 +200,57 @@ class Database {
|
|
|
200
200
|
this.db.close();
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
+
function maybePromise(arg) {
|
|
204
|
+
let lazy = arg;
|
|
205
|
+
let promise = null;
|
|
206
|
+
let value = null;
|
|
207
|
+
return {
|
|
208
|
+
apply(fn) {
|
|
209
|
+
let previous = lazy;
|
|
210
|
+
lazy = async () => {
|
|
211
|
+
const result = await previous();
|
|
212
|
+
fn(result);
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
async resolve() {
|
|
217
|
+
if (promise != null) {
|
|
218
|
+
return await promise;
|
|
219
|
+
}
|
|
220
|
+
let valueResolve, valueReject;
|
|
221
|
+
promise = new Promise((resolve, reject) => {
|
|
222
|
+
valueResolve = x => { resolve(x); value = x; };
|
|
223
|
+
valueReject = reject;
|
|
224
|
+
});
|
|
225
|
+
await lazy().then(valueResolve, valueReject);
|
|
226
|
+
return await promise;
|
|
227
|
+
},
|
|
228
|
+
must() {
|
|
229
|
+
if (value == null) {
|
|
230
|
+
throw new Error(`database must be connected before execution the function`);
|
|
231
|
+
}
|
|
232
|
+
return value;
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function maybeValue(value) {
|
|
237
|
+
return {
|
|
238
|
+
apply(fn) { fn(value); },
|
|
239
|
+
resolve() { return Promise.resolve(value); },
|
|
240
|
+
must() { return value; },
|
|
241
|
+
};
|
|
242
|
+
}
|
|
203
243
|
/**
|
|
204
244
|
* Statement represents a prepared SQL statement that can be executed.
|
|
205
245
|
*/
|
|
206
246
|
class Statement {
|
|
207
247
|
stmt;
|
|
208
248
|
db;
|
|
209
|
-
|
|
249
|
+
execLock;
|
|
250
|
+
constructor(stmt, db, execLock) {
|
|
210
251
|
this.stmt = stmt;
|
|
211
|
-
this.db =
|
|
252
|
+
this.db = db;
|
|
253
|
+
this.execLock = execLock;
|
|
212
254
|
}
|
|
213
255
|
/**
|
|
214
256
|
* Toggle raw mode.
|
|
@@ -216,7 +258,7 @@ class Statement {
|
|
|
216
258
|
* @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
|
|
217
259
|
*/
|
|
218
260
|
raw(raw) {
|
|
219
|
-
this.stmt.raw(raw);
|
|
261
|
+
this.stmt.apply(s => s.raw(raw));
|
|
220
262
|
return this;
|
|
221
263
|
}
|
|
222
264
|
/**
|
|
@@ -225,7 +267,7 @@ class Statement {
|
|
|
225
267
|
* @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
|
|
226
268
|
*/
|
|
227
269
|
pluck(pluckMode) {
|
|
228
|
-
this.stmt.pluck(pluckMode);
|
|
270
|
+
this.stmt.apply(s => s.pluck(pluckMode));
|
|
229
271
|
return this;
|
|
230
272
|
}
|
|
231
273
|
/**
|
|
@@ -234,7 +276,7 @@ class Statement {
|
|
|
234
276
|
* @param {boolean} [toggle] - Whether to use safe integers.
|
|
235
277
|
*/
|
|
236
278
|
safeIntegers(toggle) {
|
|
237
|
-
this.stmt.safeIntegers(toggle);
|
|
279
|
+
this.stmt.apply(s => s.safeIntegers(toggle));
|
|
238
280
|
return this;
|
|
239
281
|
}
|
|
240
282
|
/**
|
|
@@ -243,7 +285,7 @@ class Statement {
|
|
|
243
285
|
* @returns {Array} An array of column objects with name, column, table, database, and type properties.
|
|
244
286
|
*/
|
|
245
287
|
columns() {
|
|
246
|
-
return this.stmt.columns();
|
|
288
|
+
return this.stmt.must().columns();
|
|
247
289
|
}
|
|
248
290
|
get source() {
|
|
249
291
|
throw new Error("not implemented");
|
|
@@ -258,15 +300,16 @@ class Statement {
|
|
|
258
300
|
* Executes the SQL statement and returns an info object.
|
|
259
301
|
*/
|
|
260
302
|
async run(...bindParameters) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
bindParams(
|
|
264
|
-
|
|
303
|
+
let stmt = await this.stmt.resolve();
|
|
304
|
+
stmt.reset();
|
|
305
|
+
bindParams(stmt, bindParameters);
|
|
306
|
+
const totalChangesBefore = this.db.totalChanges();
|
|
307
|
+
await this.execLock.acquire();
|
|
265
308
|
try {
|
|
266
309
|
while (true) {
|
|
267
|
-
const stepResult = await
|
|
310
|
+
const stepResult = await stmt.stepSync();
|
|
268
311
|
if (stepResult === STEP_IO) {
|
|
269
|
-
await this.db.
|
|
312
|
+
await this.db.ioLoopAsync();
|
|
270
313
|
continue;
|
|
271
314
|
}
|
|
272
315
|
if (stepResult === STEP_DONE) {
|
|
@@ -277,12 +320,12 @@ class Statement {
|
|
|
277
320
|
continue;
|
|
278
321
|
}
|
|
279
322
|
}
|
|
280
|
-
const lastInsertRowid = this.db.
|
|
281
|
-
const changes = this.db.
|
|
323
|
+
const lastInsertRowid = this.db.lastInsertRowid();
|
|
324
|
+
const changes = this.db.totalChanges() === totalChangesBefore ? 0 : this.db.changes();
|
|
282
325
|
return { changes, lastInsertRowid };
|
|
283
326
|
}
|
|
284
327
|
finally {
|
|
285
|
-
this.
|
|
328
|
+
this.execLock.release();
|
|
286
329
|
}
|
|
287
330
|
}
|
|
288
331
|
/**
|
|
@@ -291,26 +334,27 @@ class Statement {
|
|
|
291
334
|
* @param bindParameters - The bind parameters for executing the statement.
|
|
292
335
|
*/
|
|
293
336
|
async get(...bindParameters) {
|
|
294
|
-
this.stmt.
|
|
295
|
-
|
|
296
|
-
|
|
337
|
+
let stmt = await this.stmt.resolve();
|
|
338
|
+
stmt.reset();
|
|
339
|
+
bindParams(stmt, bindParameters);
|
|
340
|
+
await this.execLock.acquire();
|
|
297
341
|
try {
|
|
298
342
|
while (true) {
|
|
299
|
-
const stepResult = await
|
|
343
|
+
const stepResult = await stmt.stepSync();
|
|
300
344
|
if (stepResult === STEP_IO) {
|
|
301
|
-
await this.db.
|
|
345
|
+
await this.db.ioLoopAsync();
|
|
302
346
|
continue;
|
|
303
347
|
}
|
|
304
348
|
if (stepResult === STEP_DONE) {
|
|
305
349
|
return undefined;
|
|
306
350
|
}
|
|
307
351
|
if (stepResult === STEP_ROW) {
|
|
308
|
-
return
|
|
352
|
+
return stmt.row();
|
|
309
353
|
}
|
|
310
354
|
}
|
|
311
355
|
}
|
|
312
356
|
finally {
|
|
313
|
-
this.
|
|
357
|
+
this.execLock.release();
|
|
314
358
|
}
|
|
315
359
|
}
|
|
316
360
|
/**
|
|
@@ -319,26 +363,27 @@ class Statement {
|
|
|
319
363
|
* @param bindParameters - The bind parameters for executing the statement.
|
|
320
364
|
*/
|
|
321
365
|
async *iterate(...bindParameters) {
|
|
322
|
-
this.stmt.
|
|
323
|
-
|
|
324
|
-
|
|
366
|
+
let stmt = await this.stmt.resolve();
|
|
367
|
+
stmt.reset();
|
|
368
|
+
bindParams(stmt, bindParameters);
|
|
369
|
+
await this.execLock.acquire();
|
|
325
370
|
try {
|
|
326
371
|
while (true) {
|
|
327
|
-
const stepResult = await
|
|
372
|
+
const stepResult = await stmt.stepSync();
|
|
328
373
|
if (stepResult === STEP_IO) {
|
|
329
|
-
await this.db.
|
|
374
|
+
await this.db.ioLoopAsync();
|
|
330
375
|
continue;
|
|
331
376
|
}
|
|
332
377
|
if (stepResult === STEP_DONE) {
|
|
333
378
|
break;
|
|
334
379
|
}
|
|
335
380
|
if (stepResult === STEP_ROW) {
|
|
336
|
-
yield
|
|
381
|
+
yield stmt.row();
|
|
337
382
|
}
|
|
338
383
|
}
|
|
339
384
|
}
|
|
340
385
|
finally {
|
|
341
|
-
this.
|
|
386
|
+
this.execLock.release();
|
|
342
387
|
}
|
|
343
388
|
}
|
|
344
389
|
/**
|
|
@@ -347,28 +392,29 @@ class Statement {
|
|
|
347
392
|
* @param bindParameters - The bind parameters for executing the statement.
|
|
348
393
|
*/
|
|
349
394
|
async all(...bindParameters) {
|
|
350
|
-
this.stmt.
|
|
351
|
-
|
|
395
|
+
let stmt = await this.stmt.resolve();
|
|
396
|
+
stmt.reset();
|
|
397
|
+
bindParams(stmt, bindParameters);
|
|
352
398
|
const rows = [];
|
|
353
|
-
await this.
|
|
399
|
+
await this.execLock.acquire();
|
|
354
400
|
try {
|
|
355
401
|
while (true) {
|
|
356
|
-
const stepResult = await
|
|
402
|
+
const stepResult = await stmt.stepSync();
|
|
357
403
|
if (stepResult === STEP_IO) {
|
|
358
|
-
await this.db.
|
|
404
|
+
await this.db.ioLoopAsync();
|
|
359
405
|
continue;
|
|
360
406
|
}
|
|
361
407
|
if (stepResult === STEP_DONE) {
|
|
362
408
|
break;
|
|
363
409
|
}
|
|
364
410
|
if (stepResult === STEP_ROW) {
|
|
365
|
-
rows.push(
|
|
411
|
+
rows.push(stmt.row());
|
|
366
412
|
}
|
|
367
413
|
}
|
|
368
414
|
return rows;
|
|
369
415
|
}
|
|
370
416
|
finally {
|
|
371
|
-
this.
|
|
417
|
+
this.execLock.release();
|
|
372
418
|
}
|
|
373
419
|
}
|
|
374
420
|
/**
|
|
@@ -393,7 +439,15 @@ class Statement {
|
|
|
393
439
|
}
|
|
394
440
|
}
|
|
395
441
|
close() {
|
|
396
|
-
|
|
442
|
+
let stmt;
|
|
443
|
+
try {
|
|
444
|
+
stmt = this.stmt.must();
|
|
445
|
+
}
|
|
446
|
+
catch (e) {
|
|
447
|
+
// ignore error - if stmt wasn't initialized it's fine
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
stmt.finalize();
|
|
397
451
|
}
|
|
398
452
|
}
|
|
399
|
-
export { Database, Statement };
|
|
453
|
+
export { Database, Statement, maybePromise, maybeValue };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise.test.d.ts","sourceRoot":"","sources":["../promise.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
import { maybePromise } from './promise.js';
|
|
3
|
+
test('drizzle-orm', async () => {
|
|
4
|
+
const lazy = maybePromise(() => fetch('http://google.com'));
|
|
5
|
+
let status, headers;
|
|
6
|
+
//@ts-ignore
|
|
7
|
+
lazy.apply(x => { status = x.status; });
|
|
8
|
+
//@ts-ignore
|
|
9
|
+
lazy.apply(x => { headers = x.headers; });
|
|
10
|
+
let response = await lazy.resolve();
|
|
11
|
+
expect(response).not.toBeNull();
|
|
12
|
+
expect(status).toBe(200);
|
|
13
|
+
expect(headers).not.toBeNull();
|
|
14
|
+
});
|
package/dist/types.d.ts
CHANGED
|
@@ -2,18 +2,20 @@ export interface DatabaseOpts {
|
|
|
2
2
|
readonly?: boolean;
|
|
3
3
|
fileMustExist?: boolean;
|
|
4
4
|
timeout?: number;
|
|
5
|
-
name?: string;
|
|
6
5
|
tracing?: 'info' | 'debug' | 'trace';
|
|
7
6
|
}
|
|
8
7
|
export interface NativeDatabase {
|
|
9
8
|
memory: boolean;
|
|
10
9
|
path: string;
|
|
10
|
+
readonly: boolean;
|
|
11
|
+
open: boolean;
|
|
11
12
|
new (path: string): NativeDatabase;
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
connectSync(): any;
|
|
14
|
+
connectAsync(): Promise<void>;
|
|
14
15
|
ioLoopSync(): any;
|
|
15
16
|
ioLoopAsync(): Promise<void>;
|
|
16
17
|
prepare(sql: string): NativeStatement;
|
|
18
|
+
executor(sql: string): NativeExecutor;
|
|
17
19
|
defaultSafeIntegers(toggle: boolean): any;
|
|
18
20
|
totalChanges(): number;
|
|
19
21
|
changes(): number;
|
|
@@ -27,6 +29,10 @@ export interface TableColumn {
|
|
|
27
29
|
name: string;
|
|
28
30
|
type: string;
|
|
29
31
|
}
|
|
32
|
+
export interface NativeExecutor {
|
|
33
|
+
stepSync(): number;
|
|
34
|
+
reset(): any;
|
|
35
|
+
}
|
|
30
36
|
export interface NativeStatement {
|
|
31
37
|
stepAsync(): Promise<number>;
|
|
32
38
|
stepSync(): number;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;CACvC;AAED,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,KAAI,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;IAElC,WAAW,QAAG;IACd,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9B,UAAU,QAAG;IACb,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC;IAEtC,mBAAmB,CAAC,MAAM,EAAE,OAAO,OAAE;IACrC,YAAY,IAAI,MAAM,CAAC;IACvB,OAAO,IAAI,MAAM,CAAC;IAClB,eAAe,IAAI,MAAM,CAAC;IAC1B,KAAK,QAAG;CACX;AAID,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,eAAO,MAAM,OAAO,IAAI,CAAC;AAEzB,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,cAAc;IAC3B,QAAQ,IAAI,MAAM,CAAC;IACnB,KAAK,QAAG;CACX;AACD,MAAM,WAAW,eAAe;IAC5B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,QAAQ,IAAI,MAAM,CAAC;IAEnB,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tursodatabase/database-common",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/tursodatabase/turso"
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
"README.md"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"typescript": "^5.9.2"
|
|
18
|
+
"typescript": "^5.9.2",
|
|
19
|
+
"vitest": "^3.2.4"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
22
|
"tsc-build": "npm exec tsc",
|
|
22
23
|
"build": "npm run tsc-build",
|
|
23
|
-
"test": "
|
|
24
|
+
"test": "vitest --run"
|
|
24
25
|
}
|
|
25
26
|
}
|