@tursodatabase/database-common 0.1.5-pre.3

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 ADDED
@@ -0,0 +1,8 @@
1
+ ## About
2
+
3
+ This package is the Turso embedded database common JS library which is shared between final builds for Node and Browser.
4
+
5
+ Do not use this package directly - instead you must use `@tursodatabase/database` or `@tursodatabase/database-browser`.
6
+
7
+ > **⚠️ Warning:** This software is ALPHA, only use for development, testing, and experimentation. We are working to make it production ready, but do not use it for critical data right now.
8
+
package/dist/bind.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function bindParams(stmt: any, params: any): void;
2
+ //# sourceMappingURL=bind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../bind.ts"],"names":[],"mappings":"AASA,wBAAgB,UAAU,CAAC,IAAI,KAAA,EAAE,MAAM,KAAA,QAmBtC"}
package/dist/bind.js ADDED
@@ -0,0 +1,68 @@
1
+ // Bind parameters to a statement.
2
+ //
3
+ // This function is used to bind parameters to a statement. It supports both
4
+ // named and positional parameters, and nested arrays.
5
+ //
6
+ // The `stmt` parameter is a statement object.
7
+ // The `params` parameter is an array of parameters.
8
+ //
9
+ // The function returns void.
10
+ export function bindParams(stmt, params) {
11
+ const len = params?.length;
12
+ if (len === 0) {
13
+ return;
14
+ }
15
+ if (len === 1) {
16
+ const param = params[0];
17
+ if (isPlainObject(param)) {
18
+ bindNamedParams(stmt, param);
19
+ return;
20
+ }
21
+ if (Array.isArray(param)) {
22
+ bindPositionalParams(stmt, [param]);
23
+ return;
24
+ }
25
+ bindValue(stmt, 1, param);
26
+ return;
27
+ }
28
+ bindPositionalParams(stmt, params);
29
+ }
30
+ // Check if object is plain (no prototype chain)
31
+ function isPlainObject(obj) {
32
+ if (!obj || typeof obj !== 'object')
33
+ return false;
34
+ const proto = Object.getPrototypeOf(obj);
35
+ return proto === Object.prototype || proto === null;
36
+ }
37
+ // Handle named parameters
38
+ function bindNamedParams(stmt, paramObj) {
39
+ const paramCount = stmt.parameterCount();
40
+ for (let i = 1; i <= paramCount; i++) {
41
+ const paramName = stmt.parameterName(i);
42
+ if (paramName) {
43
+ const key = paramName.substring(1); // Remove ':' or '$' prefix
44
+ const value = paramObj[key];
45
+ if (value !== undefined) {
46
+ bindValue(stmt, i, value);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ // Handle positional parameters (including nested arrays)
52
+ function bindPositionalParams(stmt, params) {
53
+ let bindIndex = 1;
54
+ for (let i = 0; i < params.length; i++) {
55
+ const param = params[i];
56
+ if (Array.isArray(param)) {
57
+ for (let j = 0; j < param.length; j++) {
58
+ bindValue(stmt, bindIndex++, param[j]);
59
+ }
60
+ }
61
+ else {
62
+ bindValue(stmt, bindIndex++, param);
63
+ }
64
+ }
65
+ }
66
+ function bindValue(stmt, index, value) {
67
+ stmt.bindAt(index, value);
68
+ }
@@ -0,0 +1,134 @@
1
+ import { NativeDatabase, NativeStatement } from "./types.js";
2
+ /**
3
+ * Database represents a connection that can prepare and execute SQL statements.
4
+ */
5
+ declare class Database {
6
+ db: NativeDatabase;
7
+ memory: boolean;
8
+ open: boolean;
9
+ private _inTransaction;
10
+ /**
11
+ * Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
12
+ *
13
+ * @constructor
14
+ * @param {string} path - Path to the database file.
15
+ * @param {Object} opts - Options for database behavior.
16
+ * @param {boolean} [opts.readonly=false] - Open the database in read-only mode.
17
+ * @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
18
+ * @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
19
+ */
20
+ constructor(db: NativeDatabase, opts?: any);
21
+ /**
22
+ * Prepares a SQL statement for execution.
23
+ *
24
+ * @param {string} sql - The SQL statement string to prepare.
25
+ */
26
+ prepare(sql: any): Statement;
27
+ /**
28
+ * Returns a function that executes the given function in a transaction.
29
+ *
30
+ * @param {function} fn - The function to wrap in a transaction.
31
+ */
32
+ transaction(fn: any): (...bindParameters: any[]) => any;
33
+ pragma(source: any, options: any): any[];
34
+ backup(filename: any, options: any): void;
35
+ serialize(options: any): void;
36
+ function(name: any, options: any, fn: any): void;
37
+ aggregate(name: any, options: any): void;
38
+ table(name: any, factory: any): void;
39
+ loadExtension(path: any): void;
40
+ maxWriteReplicationIndex(): void;
41
+ /**
42
+ * Executes a SQL statement.
43
+ *
44
+ * @param {string} sql - The SQL statement string to execute.
45
+ */
46
+ exec(sql: any): void;
47
+ /**
48
+ * Interrupts the database connection.
49
+ */
50
+ interrupt(): void;
51
+ /**
52
+ * Sets the default safe integers mode for all statements from this database.
53
+ *
54
+ * @param {boolean} [toggle] - Whether to use safe integers by default.
55
+ */
56
+ defaultSafeIntegers(toggle: any): void;
57
+ /**
58
+ * Closes the database connection.
59
+ */
60
+ close(): void;
61
+ }
62
+ /**
63
+ * Statement represents a prepared SQL statement that can be executed.
64
+ */
65
+ declare class Statement {
66
+ stmt: NativeStatement;
67
+ db: Database;
68
+ constructor(stmt: NativeStatement, database: Database);
69
+ /**
70
+ * Toggle raw mode.
71
+ *
72
+ * @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
73
+ */
74
+ raw(raw: any): this;
75
+ /**
76
+ * Toggle pluck mode.
77
+ *
78
+ * @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
79
+ */
80
+ pluck(pluckMode: any): this;
81
+ /**
82
+ * Sets safe integers mode for this statement.
83
+ *
84
+ * @param {boolean} [toggle] - Whether to use safe integers.
85
+ */
86
+ safeIntegers(toggle: any): this;
87
+ /**
88
+ * Get column information for the statement.
89
+ *
90
+ * @returns {Array} An array of column objects with name, column, table, database, and type properties.
91
+ */
92
+ columns(): string[];
93
+ get source(): void;
94
+ get reader(): void;
95
+ get database(): Database;
96
+ /**
97
+ * Executes the SQL statement and returns an info object.
98
+ */
99
+ run(...bindParameters: any[]): {
100
+ changes: number;
101
+ lastInsertRowid: number;
102
+ };
103
+ /**
104
+ * Executes the SQL statement and returns the first row.
105
+ *
106
+ * @param bindParameters - The bind parameters for executing the statement.
107
+ */
108
+ get(...bindParameters: any[]): any;
109
+ /**
110
+ * Executes the SQL statement and returns an iterator to the resulting rows.
111
+ *
112
+ * @param bindParameters - The bind parameters for executing the statement.
113
+ */
114
+ iterate(...bindParameters: any[]): Generator<any, void, unknown>;
115
+ /**
116
+ * Executes the SQL statement and returns an array of the resulting rows.
117
+ *
118
+ * @param bindParameters - The bind parameters for executing the statement.
119
+ */
120
+ all(...bindParameters: any[]): any[];
121
+ /**
122
+ * Interrupts the statement.
123
+ */
124
+ interrupt(): void;
125
+ /**
126
+ * Binds the given parameters to the statement _permanently_
127
+ *
128
+ * @param bindParameters - The bind parameters for binding the statement.
129
+ * @returns this - Statement with binded parameters
130
+ */
131
+ bind(...bindParameters: any[]): this;
132
+ }
133
+ export { Database, Statement };
134
+ //# sourceMappingURL=compat.d.ts.map
@@ -0,0 +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,cAAc,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,cAAc,CAAkB;IAExC;;;;;;;;;OASG;gBACS,EAAE,EAAE,cAAc,EAAE,IAAI,GAAE,GAAQ;IA+B9C;;;;OAIG;IACH,OAAO,CAAC,GAAG,KAAA;IAgBX;;;;OAIG;IACH,WAAW,CAAC,EAAE,KAAA;IAmCd,MAAM,CAAC,MAAM,KAAA,EAAE,OAAO,KAAA;IAiBtB,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;;;;OAIG;IACH,IAAI,CAAC,GAAG,KAAA;IAYR;;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,QAAQ,CAAC;gBAED,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ;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,aAEX;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;CAQvB;AAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAA"}
package/dist/compat.js ADDED
@@ -0,0 +1,362 @@
1
+ import { bindParams } from "./bind.js";
2
+ import { SqliteError } from "./sqlite-error.js";
3
+ import { STEP_IO, STEP_ROW, STEP_DONE } from "./types.js";
4
+ const convertibleErrorTypes = { TypeError };
5
+ const CONVERTIBLE_ERROR_PREFIX = "[TURSO_CONVERT_TYPE]";
6
+ function convertError(err) {
7
+ if ((err.code ?? "").startsWith(CONVERTIBLE_ERROR_PREFIX)) {
8
+ return createErrorByName(err.code.substring(CONVERTIBLE_ERROR_PREFIX.length), err.message);
9
+ }
10
+ return new SqliteError(err.message, err.code, err.rawCode);
11
+ }
12
+ function createErrorByName(name, message) {
13
+ const ErrorConstructor = convertibleErrorTypes[name];
14
+ if (!ErrorConstructor) {
15
+ throw new Error(`unknown error type ${name} from Turso`);
16
+ }
17
+ return new ErrorConstructor(message);
18
+ }
19
+ /**
20
+ * Database represents a connection that can prepare and execute SQL statements.
21
+ */
22
+ class Database {
23
+ db;
24
+ memory;
25
+ open;
26
+ _inTransaction = false;
27
+ /**
28
+ * Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
29
+ *
30
+ * @constructor
31
+ * @param {string} path - Path to the database file.
32
+ * @param {Object} opts - Options for database behavior.
33
+ * @param {boolean} [opts.readonly=false] - Open the database in read-only mode.
34
+ * @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
35
+ * @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
36
+ */
37
+ constructor(db, opts = {}) {
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;
42
+ this.db = db;
43
+ this.memory = this.db.memory;
44
+ Object.defineProperties(this, {
45
+ inTransaction: {
46
+ get: () => this._inTransaction,
47
+ },
48
+ name: {
49
+ get() {
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
+ },
63
+ });
64
+ }
65
+ /**
66
+ * Prepares a SQL statement for execution.
67
+ *
68
+ * @param {string} sql - The SQL statement string to prepare.
69
+ */
70
+ prepare(sql) {
71
+ if (!this.open) {
72
+ throw new TypeError("The database connection is not open");
73
+ }
74
+ if (!sql) {
75
+ throw new RangeError("The supplied SQL string contains no statements");
76
+ }
77
+ try {
78
+ return new Statement(this.db.prepare(sql), this);
79
+ }
80
+ catch (err) {
81
+ throw convertError(err);
82
+ }
83
+ }
84
+ /**
85
+ * Returns a function that executes the given function in a transaction.
86
+ *
87
+ * @param {function} fn - The function to wrap in a transaction.
88
+ */
89
+ transaction(fn) {
90
+ if (typeof fn !== "function")
91
+ throw new TypeError("Expected first argument to be a function");
92
+ const db = this;
93
+ const wrapTxn = (mode) => {
94
+ return (...bindParameters) => {
95
+ db.exec("BEGIN " + mode);
96
+ db._inTransaction = true;
97
+ try {
98
+ const result = fn(...bindParameters);
99
+ db.exec("COMMIT");
100
+ db._inTransaction = false;
101
+ return result;
102
+ }
103
+ catch (err) {
104
+ db.exec("ROLLBACK");
105
+ db._inTransaction = false;
106
+ throw err;
107
+ }
108
+ };
109
+ };
110
+ const properties = {
111
+ default: { value: wrapTxn("") },
112
+ deferred: { value: wrapTxn("DEFERRED") },
113
+ immediate: { value: wrapTxn("IMMEDIATE") },
114
+ exclusive: { value: wrapTxn("EXCLUSIVE") },
115
+ database: { value: this, enumerable: true },
116
+ };
117
+ Object.defineProperties(properties.default.value, properties);
118
+ Object.defineProperties(properties.deferred.value, properties);
119
+ Object.defineProperties(properties.immediate.value, properties);
120
+ Object.defineProperties(properties.exclusive.value, properties);
121
+ return properties.default.value;
122
+ }
123
+ pragma(source, options) {
124
+ if (options == null)
125
+ options = {};
126
+ if (typeof source !== "string")
127
+ throw new TypeError("Expected first argument to be a string");
128
+ if (typeof options !== "object")
129
+ throw new TypeError("Expected second argument to be an options object");
130
+ const pragma = `PRAGMA ${source}`;
131
+ const stmt = this.prepare(pragma);
132
+ const results = stmt.all();
133
+ return results;
134
+ }
135
+ backup(filename, options) {
136
+ throw new Error("not implemented");
137
+ }
138
+ serialize(options) {
139
+ throw new Error("not implemented");
140
+ }
141
+ function(name, options, fn) {
142
+ throw new Error("not implemented");
143
+ }
144
+ aggregate(name, options) {
145
+ throw new Error("not implemented");
146
+ }
147
+ table(name, factory) {
148
+ throw new Error("not implemented");
149
+ }
150
+ loadExtension(path) {
151
+ throw new Error("not implemented");
152
+ }
153
+ maxWriteReplicationIndex() {
154
+ throw new Error("not implemented");
155
+ }
156
+ /**
157
+ * Executes a SQL statement.
158
+ *
159
+ * @param {string} sql - The SQL statement string to execute.
160
+ */
161
+ exec(sql) {
162
+ if (!this.open) {
163
+ throw new TypeError("The database connection is not open");
164
+ }
165
+ try {
166
+ this.db.batchSync(sql);
167
+ }
168
+ catch (err) {
169
+ throw convertError(err);
170
+ }
171
+ }
172
+ /**
173
+ * Interrupts the database connection.
174
+ */
175
+ interrupt() {
176
+ throw new Error("not implemented");
177
+ }
178
+ /**
179
+ * Sets the default safe integers mode for all statements from this database.
180
+ *
181
+ * @param {boolean} [toggle] - Whether to use safe integers by default.
182
+ */
183
+ defaultSafeIntegers(toggle) {
184
+ this.db.defaultSafeIntegers(toggle);
185
+ }
186
+ /**
187
+ * Closes the database connection.
188
+ */
189
+ close() {
190
+ this.db.close();
191
+ }
192
+ }
193
+ /**
194
+ * Statement represents a prepared SQL statement that can be executed.
195
+ */
196
+ class Statement {
197
+ stmt;
198
+ db;
199
+ constructor(stmt, database) {
200
+ this.stmt = stmt;
201
+ this.db = database;
202
+ }
203
+ /**
204
+ * Toggle raw mode.
205
+ *
206
+ * @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
207
+ */
208
+ raw(raw) {
209
+ this.stmt.raw(raw);
210
+ return this;
211
+ }
212
+ /**
213
+ * Toggle pluck mode.
214
+ *
215
+ * @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
216
+ */
217
+ pluck(pluckMode) {
218
+ this.stmt.pluck(pluckMode);
219
+ return this;
220
+ }
221
+ /**
222
+ * Sets safe integers mode for this statement.
223
+ *
224
+ * @param {boolean} [toggle] - Whether to use safe integers.
225
+ */
226
+ safeIntegers(toggle) {
227
+ this.stmt.safeIntegers(toggle);
228
+ return this;
229
+ }
230
+ /**
231
+ * Get column information for the statement.
232
+ *
233
+ * @returns {Array} An array of column objects with name, column, table, database, and type properties.
234
+ */
235
+ columns() {
236
+ return this.stmt.columns();
237
+ }
238
+ get source() {
239
+ throw new Error("not implemented");
240
+ }
241
+ get reader() {
242
+ throw new Error("not implemented");
243
+ }
244
+ get database() {
245
+ return this.db;
246
+ }
247
+ /**
248
+ * Executes the SQL statement and returns an info object.
249
+ */
250
+ run(...bindParameters) {
251
+ const totalChangesBefore = this.db.db.totalChanges();
252
+ this.stmt.reset();
253
+ bindParams(this.stmt, bindParameters);
254
+ for (;;) {
255
+ const stepResult = this.stmt.stepSync();
256
+ if (stepResult === STEP_IO) {
257
+ this.db.db.ioLoopSync();
258
+ continue;
259
+ }
260
+ if (stepResult === STEP_DONE) {
261
+ break;
262
+ }
263
+ if (stepResult === STEP_ROW) {
264
+ // For run(), we don't need the row data, just continue
265
+ continue;
266
+ }
267
+ }
268
+ const lastInsertRowid = this.db.db.lastInsertRowid();
269
+ const changes = this.db.db.totalChanges() === totalChangesBefore ? 0 : this.db.db.changes();
270
+ return { changes, lastInsertRowid };
271
+ }
272
+ /**
273
+ * Executes the SQL statement and returns the first row.
274
+ *
275
+ * @param bindParameters - The bind parameters for executing the statement.
276
+ */
277
+ get(...bindParameters) {
278
+ this.stmt.reset();
279
+ bindParams(this.stmt, bindParameters);
280
+ for (;;) {
281
+ const stepResult = this.stmt.stepSync();
282
+ if (stepResult === STEP_IO) {
283
+ this.db.db.ioLoopSync();
284
+ continue;
285
+ }
286
+ if (stepResult === STEP_DONE) {
287
+ return undefined;
288
+ }
289
+ if (stepResult === STEP_ROW) {
290
+ return this.stmt.row();
291
+ }
292
+ }
293
+ }
294
+ /**
295
+ * Executes the SQL statement and returns an iterator to the resulting rows.
296
+ *
297
+ * @param bindParameters - The bind parameters for executing the statement.
298
+ */
299
+ *iterate(...bindParameters) {
300
+ this.stmt.reset();
301
+ bindParams(this.stmt, bindParameters);
302
+ while (true) {
303
+ const stepResult = this.stmt.stepSync();
304
+ if (stepResult === STEP_IO) {
305
+ this.db.db.ioLoopSync();
306
+ continue;
307
+ }
308
+ if (stepResult === STEP_DONE) {
309
+ break;
310
+ }
311
+ if (stepResult === STEP_ROW) {
312
+ yield this.stmt.row();
313
+ }
314
+ }
315
+ }
316
+ /**
317
+ * Executes the SQL statement and returns an array of the resulting rows.
318
+ *
319
+ * @param bindParameters - The bind parameters for executing the statement.
320
+ */
321
+ all(...bindParameters) {
322
+ this.stmt.reset();
323
+ bindParams(this.stmt, bindParameters);
324
+ const rows = [];
325
+ for (;;) {
326
+ const stepResult = this.stmt.stepSync();
327
+ if (stepResult === STEP_IO) {
328
+ this.db.db.ioLoopSync();
329
+ continue;
330
+ }
331
+ if (stepResult === STEP_DONE) {
332
+ break;
333
+ }
334
+ if (stepResult === STEP_ROW) {
335
+ rows.push(this.stmt.row());
336
+ }
337
+ }
338
+ return rows;
339
+ }
340
+ /**
341
+ * Interrupts the statement.
342
+ */
343
+ interrupt() {
344
+ throw new Error("not implemented");
345
+ }
346
+ /**
347
+ * Binds the given parameters to the statement _permanently_
348
+ *
349
+ * @param bindParameters - The bind parameters for binding the statement.
350
+ * @returns this - Statement with binded parameters
351
+ */
352
+ bind(...bindParameters) {
353
+ try {
354
+ bindParams(this.stmt, bindParameters);
355
+ return this;
356
+ }
357
+ catch (err) {
358
+ throw convertError(err);
359
+ }
360
+ }
361
+ }
362
+ export { Database, Statement };
@@ -0,0 +1,6 @@
1
+ import { NativeDatabase, NativeStatement, DatabaseOpts } from "./types.js";
2
+ import { Database as DatabaseCompat, Statement as StatementCompat } from "./compat.js";
3
+ import { Database as DatabasePromise, Statement as StatementPromise } from "./promise.js";
4
+ import { SqliteError } from "./sqlite-error.js";
5
+ export { DatabaseCompat, StatementCompat, DatabasePromise, StatementPromise, NativeDatabase, NativeStatement, SqliteError, DatabaseOpts };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAEhD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { Database as DatabaseCompat, Statement as StatementCompat } from "./compat.js";
2
+ import { Database as DatabasePromise, Statement as StatementPromise } from "./promise.js";
3
+ import { SqliteError } from "./sqlite-error.js";
4
+ export { DatabaseCompat, StatementCompat, DatabasePromise, StatementPromise, SqliteError };
@@ -0,0 +1,137 @@
1
+ import { NativeDatabase, NativeStatement, DatabaseOpts } from "./types.js";
2
+ /**
3
+ * Database represents a connection that can prepare and execute SQL statements.
4
+ */
5
+ declare class Database {
6
+ db: NativeDatabase;
7
+ memory: boolean;
8
+ open: boolean;
9
+ private _inTransaction;
10
+ /**
11
+ * Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
12
+ *
13
+ * @constructor
14
+ * @param {string} path - Path to the database file.
15
+ * @param {Object} opts - Options for database behavior.
16
+ * @param {boolean} [opts.readonly=false] - Open the database in read-only mode.
17
+ * @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
18
+ * @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
19
+ */
20
+ constructor(db: NativeDatabase, opts?: DatabaseOpts);
21
+ static create(): any;
22
+ initialize(db: NativeDatabase, name: any, readonly: any): void;
23
+ /**
24
+ * Prepares a SQL statement for execution.
25
+ *
26
+ * @param {string} sql - The SQL statement string to prepare.
27
+ */
28
+ prepare(sql: any): Statement;
29
+ /**
30
+ * Returns a function that executes the given function in a transaction.
31
+ *
32
+ * @param {function} fn - The function to wrap in a transaction.
33
+ */
34
+ transaction(fn: (...any: any[]) => Promise<any>): (...bindParameters: any[]) => Promise<any>;
35
+ pragma(source: any, options: any): Promise<any[]>;
36
+ backup(filename: any, options: any): void;
37
+ serialize(options: any): void;
38
+ function(name: any, options: any, fn: any): void;
39
+ aggregate(name: any, options: any): void;
40
+ table(name: any, factory: any): void;
41
+ loadExtension(path: any): void;
42
+ maxWriteReplicationIndex(): void;
43
+ /**
44
+ * Executes a SQL statement.
45
+ *
46
+ * @param {string} sql - The SQL statement string to execute.
47
+ */
48
+ exec(sql: any): Promise<void>;
49
+ /**
50
+ * Interrupts the database connection.
51
+ */
52
+ interrupt(): void;
53
+ /**
54
+ * Sets the default safe integers mode for all statements from this database.
55
+ *
56
+ * @param {boolean} [toggle] - Whether to use safe integers by default.
57
+ */
58
+ defaultSafeIntegers(toggle: any): void;
59
+ /**
60
+ * Closes the database connection.
61
+ */
62
+ close(): Promise<void>;
63
+ }
64
+ /**
65
+ * Statement represents a prepared SQL statement that can be executed.
66
+ */
67
+ declare class Statement {
68
+ stmt: NativeStatement;
69
+ db: Database;
70
+ constructor(stmt: any, database: any);
71
+ /**
72
+ * Toggle raw mode.
73
+ *
74
+ * @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
75
+ */
76
+ raw(raw: any): this;
77
+ /**
78
+ * Toggle pluck mode.
79
+ *
80
+ * @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
81
+ */
82
+ pluck(pluckMode: any): this;
83
+ /**
84
+ * Sets safe integers mode for this statement.
85
+ *
86
+ * @param {boolean} [toggle] - Whether to use safe integers.
87
+ */
88
+ safeIntegers(toggle: any): this;
89
+ /**
90
+ * Get column information for the statement.
91
+ *
92
+ * @returns {Array} An array of column objects with name, column, table, database, and type properties.
93
+ */
94
+ columns(): string[];
95
+ get source(): void;
96
+ get reader(): void;
97
+ get database(): Database;
98
+ /**
99
+ * Executes the SQL statement and returns an info object.
100
+ */
101
+ run(...bindParameters: any[]): Promise<{
102
+ changes: number;
103
+ lastInsertRowid: number;
104
+ }>;
105
+ /**
106
+ * Executes the SQL statement and returns the first row.
107
+ *
108
+ * @param bindParameters - The bind parameters for executing the statement.
109
+ */
110
+ get(...bindParameters: any[]): Promise<any>;
111
+ /**
112
+ * Executes the SQL statement and returns an iterator to the resulting rows.
113
+ *
114
+ * @param bindParameters - The bind parameters for executing the statement.
115
+ */
116
+ iterate(...bindParameters: any[]): AsyncGenerator<any, void, unknown>;
117
+ /**
118
+ * Executes the SQL statement and returns an array of the resulting rows.
119
+ *
120
+ * @param bindParameters - The bind parameters for executing the statement.
121
+ */
122
+ all(...bindParameters: any[]): Promise<any[]>;
123
+ /**
124
+ * Interrupts the statement.
125
+ */
126
+ interrupt(): void;
127
+ /**
128
+ * Binds the given parameters to the statement _permanently_
129
+ *
130
+ * @param bindParameters - The bind parameters for binding the statement.
131
+ * @returns this - Statement with binded parameters
132
+ */
133
+ bind(...bindParameters: any[]): this;
134
+ close(): void;
135
+ }
136
+ export { Database, Statement };
137
+ //# sourceMappingURL=promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAgC,YAAY,EAAE,MAAM,YAAY,CAAC;AAyBzG;;GAEG;AACH,cAAM,QAAQ;IACZ,EAAE,EAAE,cAAc,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,cAAc,CAAkB;IACxC;;;;;;;;;OASG;gBACS,EAAE,EAAE,cAAc,EAAE,IAAI,GAAE,YAAiB;IAQvD,MAAM,CAAC,MAAM;IAGb,UAAU,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,KAAA,EAAE,QAAQ,KAAA;IAyB7C;;;;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;IAiB5B,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;;;;OAIG;IACG,IAAI,CAAC,GAAG,KAAA;IAYd;;OAEG;IACH,SAAS;IAIT;;;;OAIG;IACH,mBAAmB,CAAC,MAAM,KAAA;IAI1B;;OAEG;IACG,KAAK;CAGZ;AAED;;GAEG;AACH,cAAM,SAAS;IACb,IAAI,EAAE,eAAe,CAAC;IACtB,EAAE,EAAE,QAAQ,CAAC;gBACD,IAAI,KAAA,EAAE,QAAQ,KAAA;IAK1B;;;;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,aAEX;IAED;;OAEG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;;;;IA2B3B;;;;OAIG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;IAmB3B;;;;OAIG;IACI,OAAO,CAAC,GAAG,cAAc,OAAA;IAmBhC;;;;OAIG;IACG,GAAG,CAAC,GAAG,cAAc,OAAA;IAqB3B;;OAEG;IACH,SAAS;IAKT;;;;;OAKG;IACH,IAAI,CAAC,GAAG,cAAc,OAAA;IAStB,KAAK;CAGN;AACD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,371 @@
1
+ import { bindParams } from "./bind.js";
2
+ import { SqliteError } from "./sqlite-error.js";
3
+ import { STEP_IO, STEP_ROW, STEP_DONE } from "./types.js";
4
+ const convertibleErrorTypes = { TypeError };
5
+ const CONVERTIBLE_ERROR_PREFIX = "[TURSO_CONVERT_TYPE]";
6
+ function convertError(err) {
7
+ if ((err.code ?? "").startsWith(CONVERTIBLE_ERROR_PREFIX)) {
8
+ return createErrorByName(err.code.substring(CONVERTIBLE_ERROR_PREFIX.length), err.message);
9
+ }
10
+ return new SqliteError(err.message, err.code, err.rawCode);
11
+ }
12
+ function createErrorByName(name, message) {
13
+ const ErrorConstructor = convertibleErrorTypes[name];
14
+ if (!ErrorConstructor) {
15
+ throw new Error(`unknown error type ${name} from Turso`);
16
+ }
17
+ return new ErrorConstructor(message);
18
+ }
19
+ /**
20
+ * Database represents a connection that can prepare and execute SQL statements.
21
+ */
22
+ class Database {
23
+ db;
24
+ memory;
25
+ open;
26
+ _inTransaction = false;
27
+ /**
28
+ * Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
29
+ *
30
+ * @constructor
31
+ * @param {string} path - Path to the database file.
32
+ * @param {Object} opts - Options for database behavior.
33
+ * @param {boolean} [opts.readonly=false] - Open the database in read-only mode.
34
+ * @param {boolean} [opts.fileMustExist=false] - If true, throws if database file does not exist.
35
+ * @param {number} [opts.timeout=0] - Timeout duration in milliseconds for database operations. Defaults to 0 (no timeout).
36
+ */
37
+ constructor(db, opts = {}) {
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;
42
+ this.initialize(db, opts.name, opts.readonly);
43
+ }
44
+ static create() {
45
+ return Object.create(this.prototype);
46
+ }
47
+ initialize(db, name, readonly) {
48
+ this.db = db;
49
+ this.memory = db.memory;
50
+ Object.defineProperties(this, {
51
+ inTransaction: {
52
+ get: () => this._inTransaction,
53
+ },
54
+ name: {
55
+ get() {
56
+ return name;
57
+ },
58
+ },
59
+ readonly: {
60
+ get() {
61
+ return readonly;
62
+ },
63
+ },
64
+ open: {
65
+ get() {
66
+ return this.db.open;
67
+ },
68
+ },
69
+ });
70
+ }
71
+ /**
72
+ * Prepares a SQL statement for execution.
73
+ *
74
+ * @param {string} sql - The SQL statement string to prepare.
75
+ */
76
+ prepare(sql) {
77
+ if (!this.open) {
78
+ throw new TypeError("The database connection is not open");
79
+ }
80
+ if (!sql) {
81
+ throw new RangeError("The supplied SQL string contains no statements");
82
+ }
83
+ try {
84
+ return new Statement(this.db.prepare(sql), this);
85
+ }
86
+ catch (err) {
87
+ throw convertError(err);
88
+ }
89
+ }
90
+ /**
91
+ * Returns a function that executes the given function in a transaction.
92
+ *
93
+ * @param {function} fn - The function to wrap in a transaction.
94
+ */
95
+ transaction(fn) {
96
+ if (typeof fn !== "function")
97
+ throw new TypeError("Expected first argument to be a function");
98
+ const db = this;
99
+ const wrapTxn = (mode) => {
100
+ return async (...bindParameters) => {
101
+ await db.exec("BEGIN " + mode);
102
+ db._inTransaction = true;
103
+ try {
104
+ const result = await fn(...bindParameters);
105
+ await db.exec("COMMIT");
106
+ db._inTransaction = false;
107
+ return result;
108
+ }
109
+ catch (err) {
110
+ await db.exec("ROLLBACK");
111
+ db._inTransaction = false;
112
+ throw err;
113
+ }
114
+ };
115
+ };
116
+ const properties = {
117
+ default: { value: wrapTxn("") },
118
+ deferred: { value: wrapTxn("DEFERRED") },
119
+ immediate: { value: wrapTxn("IMMEDIATE") },
120
+ exclusive: { value: wrapTxn("EXCLUSIVE") },
121
+ database: { value: this, enumerable: true },
122
+ };
123
+ Object.defineProperties(properties.default.value, properties);
124
+ Object.defineProperties(properties.deferred.value, properties);
125
+ Object.defineProperties(properties.immediate.value, properties);
126
+ Object.defineProperties(properties.exclusive.value, properties);
127
+ return properties.default.value;
128
+ }
129
+ async pragma(source, options) {
130
+ if (options == null)
131
+ options = {};
132
+ if (typeof source !== "string")
133
+ throw new TypeError("Expected first argument to be a string");
134
+ if (typeof options !== "object")
135
+ throw new TypeError("Expected second argument to be an options object");
136
+ const pragma = `PRAGMA ${source}`;
137
+ const stmt = await this.prepare(pragma);
138
+ const results = await stmt.all();
139
+ return results;
140
+ }
141
+ backup(filename, options) {
142
+ throw new Error("not implemented");
143
+ }
144
+ serialize(options) {
145
+ throw new Error("not implemented");
146
+ }
147
+ function(name, options, fn) {
148
+ throw new Error("not implemented");
149
+ }
150
+ aggregate(name, options) {
151
+ throw new Error("not implemented");
152
+ }
153
+ table(name, factory) {
154
+ throw new Error("not implemented");
155
+ }
156
+ loadExtension(path) {
157
+ throw new Error("not implemented");
158
+ }
159
+ maxWriteReplicationIndex() {
160
+ throw new Error("not implemented");
161
+ }
162
+ /**
163
+ * Executes a SQL statement.
164
+ *
165
+ * @param {string} sql - The SQL statement string to execute.
166
+ */
167
+ async exec(sql) {
168
+ if (!this.open) {
169
+ throw new TypeError("The database connection is not open");
170
+ }
171
+ try {
172
+ await this.db.batchAsync(sql);
173
+ }
174
+ catch (err) {
175
+ throw convertError(err);
176
+ }
177
+ }
178
+ /**
179
+ * Interrupts the database connection.
180
+ */
181
+ interrupt() {
182
+ throw new Error("not implemented");
183
+ }
184
+ /**
185
+ * Sets the default safe integers mode for all statements from this database.
186
+ *
187
+ * @param {boolean} [toggle] - Whether to use safe integers by default.
188
+ */
189
+ defaultSafeIntegers(toggle) {
190
+ this.db.defaultSafeIntegers(toggle);
191
+ }
192
+ /**
193
+ * Closes the database connection.
194
+ */
195
+ async close() {
196
+ this.db.close();
197
+ }
198
+ }
199
+ /**
200
+ * Statement represents a prepared SQL statement that can be executed.
201
+ */
202
+ class Statement {
203
+ stmt;
204
+ db;
205
+ constructor(stmt, database) {
206
+ this.stmt = stmt;
207
+ this.db = database;
208
+ }
209
+ /**
210
+ * Toggle raw mode.
211
+ *
212
+ * @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
213
+ */
214
+ raw(raw) {
215
+ this.stmt.raw(raw);
216
+ return this;
217
+ }
218
+ /**
219
+ * Toggle pluck mode.
220
+ *
221
+ * @param pluckMode Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
222
+ */
223
+ pluck(pluckMode) {
224
+ this.stmt.pluck(pluckMode);
225
+ return this;
226
+ }
227
+ /**
228
+ * Sets safe integers mode for this statement.
229
+ *
230
+ * @param {boolean} [toggle] - Whether to use safe integers.
231
+ */
232
+ safeIntegers(toggle) {
233
+ this.stmt.safeIntegers(toggle);
234
+ return this;
235
+ }
236
+ /**
237
+ * Get column information for the statement.
238
+ *
239
+ * @returns {Array} An array of column objects with name, column, table, database, and type properties.
240
+ */
241
+ columns() {
242
+ return this.stmt.columns();
243
+ }
244
+ get source() {
245
+ throw new Error("not implemented");
246
+ }
247
+ get reader() {
248
+ throw new Error("not implemented");
249
+ }
250
+ get database() {
251
+ return this.db;
252
+ }
253
+ /**
254
+ * Executes the SQL statement and returns an info object.
255
+ */
256
+ async run(...bindParameters) {
257
+ const totalChangesBefore = this.db.db.totalChanges();
258
+ this.stmt.reset();
259
+ bindParams(this.stmt, bindParameters);
260
+ while (true) {
261
+ const stepResult = await this.stmt.stepAsync();
262
+ if (stepResult === STEP_IO) {
263
+ await this.db.db.ioLoopAsync();
264
+ continue;
265
+ }
266
+ if (stepResult === STEP_DONE) {
267
+ break;
268
+ }
269
+ if (stepResult === STEP_ROW) {
270
+ // For run(), we don't need the row data, just continue
271
+ continue;
272
+ }
273
+ }
274
+ const lastInsertRowid = this.db.db.lastInsertRowid();
275
+ const changes = this.db.db.totalChanges() === totalChangesBefore ? 0 : this.db.db.changes();
276
+ return { changes, lastInsertRowid };
277
+ }
278
+ /**
279
+ * Executes the SQL statement and returns the first row.
280
+ *
281
+ * @param bindParameters - The bind parameters for executing the statement.
282
+ */
283
+ async get(...bindParameters) {
284
+ this.stmt.reset();
285
+ bindParams(this.stmt, bindParameters);
286
+ while (true) {
287
+ const stepResult = await this.stmt.stepAsync();
288
+ if (stepResult === STEP_IO) {
289
+ await this.db.db.ioLoopAsync();
290
+ continue;
291
+ }
292
+ if (stepResult === STEP_DONE) {
293
+ return undefined;
294
+ }
295
+ if (stepResult === STEP_ROW) {
296
+ return this.stmt.row();
297
+ }
298
+ }
299
+ }
300
+ /**
301
+ * Executes the SQL statement and returns an iterator to the resulting rows.
302
+ *
303
+ * @param bindParameters - The bind parameters for executing the statement.
304
+ */
305
+ async *iterate(...bindParameters) {
306
+ this.stmt.reset();
307
+ bindParams(this.stmt, bindParameters);
308
+ while (true) {
309
+ const stepResult = await this.stmt.stepAsync();
310
+ if (stepResult === STEP_IO) {
311
+ await this.db.db.ioLoopAsync();
312
+ continue;
313
+ }
314
+ if (stepResult === STEP_DONE) {
315
+ break;
316
+ }
317
+ if (stepResult === STEP_ROW) {
318
+ yield this.stmt.row();
319
+ }
320
+ }
321
+ }
322
+ /**
323
+ * Executes the SQL statement and returns an array of the resulting rows.
324
+ *
325
+ * @param bindParameters - The bind parameters for executing the statement.
326
+ */
327
+ async all(...bindParameters) {
328
+ this.stmt.reset();
329
+ bindParams(this.stmt, bindParameters);
330
+ const rows = [];
331
+ while (true) {
332
+ const stepResult = await this.stmt.stepAsync();
333
+ if (stepResult === STEP_IO) {
334
+ await this.db.db.ioLoopAsync();
335
+ continue;
336
+ }
337
+ if (stepResult === STEP_DONE) {
338
+ break;
339
+ }
340
+ if (stepResult === STEP_ROW) {
341
+ rows.push(this.stmt.row());
342
+ }
343
+ }
344
+ return rows;
345
+ }
346
+ /**
347
+ * Interrupts the statement.
348
+ */
349
+ interrupt() {
350
+ throw new Error("not implemented");
351
+ }
352
+ /**
353
+ * Binds the given parameters to the statement _permanently_
354
+ *
355
+ * @param bindParameters - The bind parameters for binding the statement.
356
+ * @returns this - Statement with binded parameters
357
+ */
358
+ bind(...bindParameters) {
359
+ try {
360
+ bindParams(this.stmt, bindParameters);
361
+ return this;
362
+ }
363
+ catch (err) {
364
+ throw convertError(err);
365
+ }
366
+ }
367
+ close() {
368
+ this.stmt.finalize();
369
+ }
370
+ }
371
+ export { Database, Statement };
@@ -0,0 +1,7 @@
1
+ export declare class SqliteError extends Error {
2
+ name: string;
3
+ code: string;
4
+ rawCode: string;
5
+ constructor(message: any, code: any, rawCode: any);
6
+ }
7
+ //# sourceMappingURL=sqlite-error.d.ts.map
@@ -0,0 +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;gBACJ,OAAO,KAAA,EAAE,IAAI,KAAA,EAAE,OAAO,KAAA;CAQnC"}
@@ -0,0 +1,12 @@
1
+ export class SqliteError extends Error {
2
+ name;
3
+ code;
4
+ rawCode;
5
+ constructor(message, code, rawCode) {
6
+ super(message);
7
+ this.name = 'SqliteError';
8
+ this.code = code;
9
+ this.rawCode = rawCode;
10
+ Error.captureStackTrace(this, SqliteError);
11
+ }
12
+ }
@@ -0,0 +1,38 @@
1
+ export interface DatabaseOpts {
2
+ readonly?: boolean;
3
+ fileMustExist?: boolean;
4
+ timeout?: number;
5
+ name?: string;
6
+ tracing?: 'info' | 'debug' | 'trace';
7
+ }
8
+ export interface NativeDatabase {
9
+ memory: boolean;
10
+ path: string;
11
+ new (path: string): NativeDatabase;
12
+ batchSync(sql: string): any;
13
+ batchAsync(sql: string): Promise<void>;
14
+ ioLoopSync(): any;
15
+ ioLoopAsync(): Promise<void>;
16
+ prepare(sql: string): NativeStatement;
17
+ pluck(pluckMode: boolean): any;
18
+ defaultSafeIntegers(toggle: boolean): any;
19
+ totalChanges(): number;
20
+ changes(): number;
21
+ lastInsertRowid(): number;
22
+ close(): any;
23
+ }
24
+ export declare const STEP_ROW = 1;
25
+ export declare const STEP_DONE = 2;
26
+ export declare const STEP_IO = 3;
27
+ export interface NativeStatement {
28
+ stepAsync(): Promise<number>;
29
+ stepSync(): number;
30
+ pluck(pluckMode: boolean): any;
31
+ safeIntegers(toggle: boolean): any;
32
+ raw(toggle: boolean): any;
33
+ columns(): string[];
34
+ row(): any;
35
+ reset(): any;
36
+ finalize(): any;
37
+ }
38
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,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,KAAI,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;IAClC,SAAS,CAAC,GAAG,EAAE,MAAM,OAAE;IACvB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC,UAAU,QAAG;IACb,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IAEtC,KAAK,CAAC,SAAS,EAAE,OAAO,OAAE;IAC1B,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,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,MAAM,EAAE,CAAC;IACpB,GAAG,IAAI,GAAG,CAAC;IACX,KAAK,QAAG;IACR,QAAQ,QAAG;CACd"}
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ // Step result constants
2
+ export const STEP_ROW = 1;
3
+ export const STEP_DONE = 2;
4
+ export const STEP_IO = 3;
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@tursodatabase/database-common",
3
+ "version": "0.1.5-pre.3",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/tursodatabase/turso"
7
+ },
8
+ "type": "module",
9
+ "license": "MIT",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "packageManager": "yarn@4.9.2",
13
+ "files": [
14
+ "dist/**",
15
+ "README.md"
16
+ ],
17
+ "devDependencies": {
18
+ "typescript": "^5.9.2"
19
+ },
20
+ "scripts": {
21
+ "tsc-build": "npm exec tsc",
22
+ "build": "npm run tsc-build",
23
+ "test": "echo 'no tests'"
24
+ }
25
+ }