@tursodatabase/database 0.2.0-pre.1 → 0.2.0-pre.11
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 +1 -1
- package/dist/compat.js +1 -1
- package/dist/compat.test.js +32 -0
- package/dist/promise.d.ts +1 -1
- package/dist/promise.d.ts.map +1 -1
- package/dist/promise.js +4 -2
- package/dist/promise.test.js +103 -2
- package/index.js +102 -52
- package/package.json +10 -7
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ This package is the Turso embedded database library for JavaScript in Node.
|
|
|
23
23
|
- **SQLite compatible:** SQLite query language and file format support ([status](https://github.com/tursodatabase/turso/blob/main/COMPAT.md)).
|
|
24
24
|
- **In-process**: No network overhead, runs directly in your Node.js process
|
|
25
25
|
- **TypeScript support**: Full TypeScript definitions included
|
|
26
|
-
- **Cross-platform**: Supports Linux (x86 and arm64), macOS, Windows (browser is supported in the separate package `@tursodatabase/database-
|
|
26
|
+
- **Cross-platform**: Supports Linux (x86 and arm64), macOS, Windows (browser is supported in the separate package `@tursodatabase/database-wasm` package)
|
|
27
27
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
package/dist/compat.js
CHANGED
|
@@ -2,7 +2,7 @@ import { DatabaseCompat, SqliteError } from "@tursodatabase/database-common";
|
|
|
2
2
|
import { Database as NativeDB } from "#index";
|
|
3
3
|
class Database extends DatabaseCompat {
|
|
4
4
|
constructor(path, opts = {}) {
|
|
5
|
-
super(new NativeDB(path,
|
|
5
|
+
super(new NativeDB(path, opts));
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
export { Database, SqliteError };
|
package/dist/compat.test.js
CHANGED
|
@@ -9,6 +9,38 @@ test('in-memory db', () => {
|
|
|
9
9
|
const rows = stmt.all([1]);
|
|
10
10
|
expect(rows).toEqual([{ x: 1 }, { x: 3 }]);
|
|
11
11
|
});
|
|
12
|
+
test('exec multiple statements', async () => {
|
|
13
|
+
const db = new Database(":memory:");
|
|
14
|
+
db.exec("CREATE TABLE t(x); INSERT INTO t VALUES (1); INSERT INTO t VALUES (2)");
|
|
15
|
+
const stmt = db.prepare("SELECT * FROM t");
|
|
16
|
+
const rows = stmt.all();
|
|
17
|
+
expect(rows).toEqual([{ x: 1 }, { x: 2 }]);
|
|
18
|
+
});
|
|
19
|
+
test('readonly-db', () => {
|
|
20
|
+
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
|
21
|
+
try {
|
|
22
|
+
{
|
|
23
|
+
const rw = new Database(path);
|
|
24
|
+
rw.exec("CREATE TABLE t(x)");
|
|
25
|
+
rw.exec("INSERT INTO t VALUES (1)");
|
|
26
|
+
rw.close();
|
|
27
|
+
}
|
|
28
|
+
{
|
|
29
|
+
const ro = new Database(path, { readonly: true });
|
|
30
|
+
expect(() => ro.exec("INSERT INTO t VALUES (2)")).toThrowError(/Resource is read-only/g);
|
|
31
|
+
expect(ro.prepare("SELECT * FROM t").all()).toEqual([{ x: 1 }]);
|
|
32
|
+
ro.close();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
unlinkSync(path);
|
|
37
|
+
unlinkSync(`${path}-wal`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
test('file-must-exist', () => {
|
|
41
|
+
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
|
42
|
+
expect(() => new Database(path, { fileMustExist: true })).toThrowError(/failed to open file/);
|
|
43
|
+
});
|
|
12
44
|
test('on-disk db', () => {
|
|
13
45
|
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
|
14
46
|
try {
|
package/dist/promise.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ declare class Database extends DatabasePromise {
|
|
|
9
9
|
* @param {Object} opts - Options for database behavior.
|
|
10
10
|
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
|
11
11
|
*/
|
|
12
|
-
declare function connect(path: string, opts?:
|
|
12
|
+
declare function connect(path: string, opts?: DatabaseOpts): Promise<Database>;
|
|
13
13
|
export { connect, Database, SqliteError };
|
|
14
14
|
//# 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,eAAe,EAAkB,WAAW,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAG3G,cAAM,QAAS,SAAQ,eAAe;gBACtB,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB;CAGpD;AAED;;;;;;GAMG;AACH,iBAAe,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,WAAW,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAG3G,cAAM,QAAS,SAAQ,eAAe;gBACtB,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB;CAGpD;AAED;;;;;;GAMG;AACH,iBAAe,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAI/E;AAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAA"}
|
package/dist/promise.js
CHANGED
|
@@ -2,7 +2,7 @@ import { DatabasePromise, SqliteError } from "@tursodatabase/database-common";
|
|
|
2
2
|
import { Database as NativeDB } from "#index";
|
|
3
3
|
class Database extends DatabasePromise {
|
|
4
4
|
constructor(path, opts = {}) {
|
|
5
|
-
super(new NativeDB(path,
|
|
5
|
+
super(new NativeDB(path, opts));
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
@@ -13,6 +13,8 @@ class Database extends DatabasePromise {
|
|
|
13
13
|
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
|
14
14
|
*/
|
|
15
15
|
async function connect(path, opts = {}) {
|
|
16
|
-
|
|
16
|
+
const db = new Database(path, opts);
|
|
17
|
+
await db.connect();
|
|
18
|
+
return db;
|
|
17
19
|
}
|
|
18
20
|
export { connect, Database, SqliteError };
|
package/dist/promise.test.js
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import { unlinkSync } from "node:fs";
|
|
2
2
|
import { expect, test } from 'vitest';
|
|
3
|
-
import { connect } from './promise.js';
|
|
4
|
-
|
|
3
|
+
import { Database, connect } from './promise.js';
|
|
4
|
+
import { sql } from 'drizzle-orm';
|
|
5
|
+
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
6
|
+
test('drizzle-orm', async () => {
|
|
7
|
+
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
|
8
|
+
try {
|
|
9
|
+
const conn = await connect(path);
|
|
10
|
+
const db = drizzle(conn);
|
|
11
|
+
await db.run('CREATE TABLE t(x, y)');
|
|
12
|
+
let tasks = [];
|
|
13
|
+
for (let i = 0; i < 1234; i++) {
|
|
14
|
+
tasks.push(db.run(sql `INSERT INTO t VALUES (${i}, randomblob(${i} * 5))`));
|
|
15
|
+
}
|
|
16
|
+
await Promise.all(tasks);
|
|
17
|
+
expect(await db.all("SELECT COUNT(*) as cnt FROM t")).toEqual([{ cnt: 1234 }]);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
unlinkSync(path);
|
|
21
|
+
unlinkSync(`${path}-wal`);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
test('in-memory-db-async', async () => {
|
|
5
25
|
const db = await connect(":memory:");
|
|
6
26
|
await db.exec("CREATE TABLE t(x)");
|
|
7
27
|
await db.exec("INSERT INTO t VALUES (1), (2), (3)");
|
|
@@ -9,6 +29,87 @@ test('in-memory db', async () => {
|
|
|
9
29
|
const rows = await stmt.all([1]);
|
|
10
30
|
expect(rows).toEqual([{ x: 1 }, { x: 3 }]);
|
|
11
31
|
});
|
|
32
|
+
test('exec multiple statements', async () => {
|
|
33
|
+
const db = await connect(":memory:");
|
|
34
|
+
await db.exec("CREATE TABLE t(x); INSERT INTO t VALUES (1); INSERT INTO t VALUES (2)");
|
|
35
|
+
const stmt = db.prepare("SELECT * FROM t");
|
|
36
|
+
const rows = await stmt.all();
|
|
37
|
+
expect(rows).toEqual([{ x: 1 }, { x: 2 }]);
|
|
38
|
+
});
|
|
39
|
+
test('readonly-db', async () => {
|
|
40
|
+
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
|
41
|
+
try {
|
|
42
|
+
{
|
|
43
|
+
const rw = await connect(path);
|
|
44
|
+
await rw.exec("CREATE TABLE t(x)");
|
|
45
|
+
await rw.exec("INSERT INTO t VALUES (1)");
|
|
46
|
+
rw.close();
|
|
47
|
+
}
|
|
48
|
+
{
|
|
49
|
+
const ro = await connect(path, { readonly: true });
|
|
50
|
+
await expect(async () => await ro.exec("INSERT INTO t VALUES (2)")).rejects.toThrowError(/Resource is read-only/g);
|
|
51
|
+
expect(await ro.prepare("SELECT * FROM t").all()).toEqual([{ x: 1 }]);
|
|
52
|
+
ro.close();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
unlinkSync(path);
|
|
57
|
+
unlinkSync(`${path}-wal`);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
test('file-must-exist', async () => {
|
|
61
|
+
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
|
62
|
+
await expect(async () => await connect(path, { fileMustExist: true })).rejects.toThrowError(/failed to open file/);
|
|
63
|
+
});
|
|
64
|
+
test('explicit connect', async () => {
|
|
65
|
+
const db = new Database(':memory:');
|
|
66
|
+
expect(() => db.prepare("SELECT 1")).toThrowError(/database must be connected/g);
|
|
67
|
+
await db.connect();
|
|
68
|
+
expect(await db.prepare("SELECT 1 as x").all()).toEqual([{ x: 1 }]);
|
|
69
|
+
});
|
|
70
|
+
test('zero-limit-bug', async () => {
|
|
71
|
+
const db = await connect(':memory:');
|
|
72
|
+
const create = db.prepare(`CREATE TABLE users (name TEXT NOT NULL);`);
|
|
73
|
+
await create.run();
|
|
74
|
+
const insert = db.prepare(`insert into "users" values (?), (?), (?);`);
|
|
75
|
+
await insert.run('John', 'Jane', 'Jack');
|
|
76
|
+
const stmt1 = db.prepare(`select * from "users" limit ?;`);
|
|
77
|
+
expect(await stmt1.all(0)).toEqual([]);
|
|
78
|
+
let rows = [{ name: 'John' }, { name: 'Jane' }, { name: 'Jack' }, { name: 'John' }, { name: 'Jane' }, { name: 'Jack' }];
|
|
79
|
+
for (const limit of [0, 1, 2, 3, 4, 5, 6, 7]) {
|
|
80
|
+
const stmt2 = db.prepare(`select * from "users" union all select * from "users" limit ?;`);
|
|
81
|
+
expect(await stmt2.all(limit)).toEqual(rows.slice(0, Math.min(limit, 6)));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
test('avg-bug', async () => {
|
|
85
|
+
const db = await connect(':memory:');
|
|
86
|
+
const create = db.prepare(`create table "aggregate_table" (
|
|
87
|
+
"id" integer primary key autoincrement not null,
|
|
88
|
+
"name" text not null,
|
|
89
|
+
"a" integer,
|
|
90
|
+
"b" integer,
|
|
91
|
+
"c" integer,
|
|
92
|
+
"null_only" integer
|
|
93
|
+
);`);
|
|
94
|
+
await create.run();
|
|
95
|
+
const insert = db.prepare(`insert into "aggregate_table" ("id", "name", "a", "b", "c", "null_only") values (null, ?, ?, ?, ?, null), (null, ?, ?, ?, ?, null), (null, ?, ?, ?, ?, null), (null, ?, ?, ?, ?, null), (null, ?, ?, ?, ?, null), (null, ?, ?, ?, ?, null), (null, ?, ?, ?, ?, null);`);
|
|
96
|
+
await insert.run('value 1', 5, 10, 20, 'value 1', 5, 20, 30, 'value 2', 10, 50, 60, 'value 3', 20, 20, null, 'value 4', null, 90, 120, 'value 5', 80, 10, null, 'value 6', null, null, 150);
|
|
97
|
+
expect(await db.prepare(`select avg("a") from "aggregate_table";`).get()).toEqual({ 'avg (aggregate_table.a)': 24 });
|
|
98
|
+
expect(await db.prepare(`select avg("null_only") from "aggregate_table";`).get()).toEqual({ 'avg (aggregate_table.null_only)': null });
|
|
99
|
+
expect(await db.prepare(`select avg(distinct "b") from "aggregate_table";`).get()).toEqual({ 'avg (DISTINCT aggregate_table.b)': 42.5 });
|
|
100
|
+
});
|
|
101
|
+
test('offset-bug', async () => {
|
|
102
|
+
const db = await connect(":memory:");
|
|
103
|
+
await db.exec(`CREATE TABLE users (
|
|
104
|
+
id INTEGER PRIMARY KEY,
|
|
105
|
+
name TEXT NOT NULL,
|
|
106
|
+
verified integer not null default 0
|
|
107
|
+
);`);
|
|
108
|
+
const insert = db.prepare(`INSERT INTO users (name) VALUES (?),(?);`);
|
|
109
|
+
await insert.run('John', 'John1');
|
|
110
|
+
const stmt = db.prepare(`SELECT * FROM users LIMIT ? OFFSET ?;`);
|
|
111
|
+
expect(await stmt.all(1, 1)).toEqual([{ id: 2, name: 'John1', verified: 0 }]);
|
|
112
|
+
});
|
|
12
113
|
test('on-disk db', async () => {
|
|
13
114
|
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
|
14
115
|
try {
|
package/index.js
CHANGED
|
@@ -67,7 +67,7 @@ const isMuslFromChildProcess = () => {
|
|
|
67
67
|
function requireNative() {
|
|
68
68
|
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
69
69
|
try {
|
|
70
|
-
|
|
70
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
71
71
|
} catch (err) {
|
|
72
72
|
loadErrors.push(err)
|
|
73
73
|
}
|
|
@@ -81,8 +81,8 @@ function requireNative() {
|
|
|
81
81
|
try {
|
|
82
82
|
const binding = require('@tursodatabase/database-android-arm64')
|
|
83
83
|
const bindingPackageVersion = require('@tursodatabase/database-android-arm64/package.json').version
|
|
84
|
-
if (bindingPackageVersion !== '0.
|
|
85
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
84
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
85
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
86
86
|
}
|
|
87
87
|
return binding
|
|
88
88
|
} catch (e) {
|
|
@@ -97,8 +97,8 @@ function requireNative() {
|
|
|
97
97
|
try {
|
|
98
98
|
const binding = require('@tursodatabase/database-android-arm-eabi')
|
|
99
99
|
const bindingPackageVersion = require('@tursodatabase/database-android-arm-eabi/package.json').version
|
|
100
|
-
if (bindingPackageVersion !== '0.
|
|
101
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
100
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
101
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
102
102
|
}
|
|
103
103
|
return binding
|
|
104
104
|
} catch (e) {
|
|
@@ -117,8 +117,8 @@ function requireNative() {
|
|
|
117
117
|
try {
|
|
118
118
|
const binding = require('@tursodatabase/database-win32-x64-msvc')
|
|
119
119
|
const bindingPackageVersion = require('@tursodatabase/database-win32-x64-msvc/package.json').version
|
|
120
|
-
if (bindingPackageVersion !== '0.
|
|
121
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
120
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
121
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
122
122
|
}
|
|
123
123
|
return binding
|
|
124
124
|
} catch (e) {
|
|
@@ -133,8 +133,8 @@ function requireNative() {
|
|
|
133
133
|
try {
|
|
134
134
|
const binding = require('@tursodatabase/database-win32-ia32-msvc')
|
|
135
135
|
const bindingPackageVersion = require('@tursodatabase/database-win32-ia32-msvc/package.json').version
|
|
136
|
-
if (bindingPackageVersion !== '0.
|
|
137
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
136
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
137
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
138
138
|
}
|
|
139
139
|
return binding
|
|
140
140
|
} catch (e) {
|
|
@@ -149,8 +149,8 @@ function requireNative() {
|
|
|
149
149
|
try {
|
|
150
150
|
const binding = require('@tursodatabase/database-win32-arm64-msvc')
|
|
151
151
|
const bindingPackageVersion = require('@tursodatabase/database-win32-arm64-msvc/package.json').version
|
|
152
|
-
if (bindingPackageVersion !== '0.
|
|
153
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
152
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
153
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
154
154
|
}
|
|
155
155
|
return binding
|
|
156
156
|
} catch (e) {
|
|
@@ -168,8 +168,8 @@ function requireNative() {
|
|
|
168
168
|
try {
|
|
169
169
|
const binding = require('@tursodatabase/database-darwin-universal')
|
|
170
170
|
const bindingPackageVersion = require('@tursodatabase/database-darwin-universal/package.json').version
|
|
171
|
-
if (bindingPackageVersion !== '0.
|
|
172
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
171
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
172
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
173
173
|
}
|
|
174
174
|
return binding
|
|
175
175
|
} catch (e) {
|
|
@@ -184,8 +184,8 @@ function requireNative() {
|
|
|
184
184
|
try {
|
|
185
185
|
const binding = require('@tursodatabase/database-darwin-x64')
|
|
186
186
|
const bindingPackageVersion = require('@tursodatabase/database-darwin-x64/package.json').version
|
|
187
|
-
if (bindingPackageVersion !== '0.
|
|
188
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
187
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
188
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
189
189
|
}
|
|
190
190
|
return binding
|
|
191
191
|
} catch (e) {
|
|
@@ -200,8 +200,8 @@ function requireNative() {
|
|
|
200
200
|
try {
|
|
201
201
|
const binding = require('@tursodatabase/database-darwin-arm64')
|
|
202
202
|
const bindingPackageVersion = require('@tursodatabase/database-darwin-arm64/package.json').version
|
|
203
|
-
if (bindingPackageVersion !== '0.
|
|
204
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
203
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
204
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
205
205
|
}
|
|
206
206
|
return binding
|
|
207
207
|
} catch (e) {
|
|
@@ -220,8 +220,8 @@ function requireNative() {
|
|
|
220
220
|
try {
|
|
221
221
|
const binding = require('@tursodatabase/database-freebsd-x64')
|
|
222
222
|
const bindingPackageVersion = require('@tursodatabase/database-freebsd-x64/package.json').version
|
|
223
|
-
if (bindingPackageVersion !== '0.
|
|
224
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
223
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
224
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
225
225
|
}
|
|
226
226
|
return binding
|
|
227
227
|
} catch (e) {
|
|
@@ -236,8 +236,8 @@ function requireNative() {
|
|
|
236
236
|
try {
|
|
237
237
|
const binding = require('@tursodatabase/database-freebsd-arm64')
|
|
238
238
|
const bindingPackageVersion = require('@tursodatabase/database-freebsd-arm64/package.json').version
|
|
239
|
-
if (bindingPackageVersion !== '0.
|
|
240
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
239
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
240
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
241
241
|
}
|
|
242
242
|
return binding
|
|
243
243
|
} catch (e) {
|
|
@@ -257,8 +257,8 @@ function requireNative() {
|
|
|
257
257
|
try {
|
|
258
258
|
const binding = require('@tursodatabase/database-linux-x64-musl')
|
|
259
259
|
const bindingPackageVersion = require('@tursodatabase/database-linux-x64-musl/package.json').version
|
|
260
|
-
if (bindingPackageVersion !== '0.
|
|
261
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
260
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
261
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
262
262
|
}
|
|
263
263
|
return binding
|
|
264
264
|
} catch (e) {
|
|
@@ -273,8 +273,8 @@ function requireNative() {
|
|
|
273
273
|
try {
|
|
274
274
|
const binding = require('@tursodatabase/database-linux-x64-gnu')
|
|
275
275
|
const bindingPackageVersion = require('@tursodatabase/database-linux-x64-gnu/package.json').version
|
|
276
|
-
if (bindingPackageVersion !== '0.
|
|
277
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
276
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
277
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
278
278
|
}
|
|
279
279
|
return binding
|
|
280
280
|
} catch (e) {
|
|
@@ -291,8 +291,8 @@ function requireNative() {
|
|
|
291
291
|
try {
|
|
292
292
|
const binding = require('@tursodatabase/database-linux-arm64-musl')
|
|
293
293
|
const bindingPackageVersion = require('@tursodatabase/database-linux-arm64-musl/package.json').version
|
|
294
|
-
if (bindingPackageVersion !== '0.
|
|
295
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
294
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
295
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
296
296
|
}
|
|
297
297
|
return binding
|
|
298
298
|
} catch (e) {
|
|
@@ -307,8 +307,8 @@ function requireNative() {
|
|
|
307
307
|
try {
|
|
308
308
|
const binding = require('@tursodatabase/database-linux-arm64-gnu')
|
|
309
309
|
const bindingPackageVersion = require('@tursodatabase/database-linux-arm64-gnu/package.json').version
|
|
310
|
-
if (bindingPackageVersion !== '0.
|
|
311
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
310
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
311
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
312
312
|
}
|
|
313
313
|
return binding
|
|
314
314
|
} catch (e) {
|
|
@@ -325,8 +325,8 @@ function requireNative() {
|
|
|
325
325
|
try {
|
|
326
326
|
const binding = require('@tursodatabase/database-linux-arm-musleabihf')
|
|
327
327
|
const bindingPackageVersion = require('@tursodatabase/database-linux-arm-musleabihf/package.json').version
|
|
328
|
-
if (bindingPackageVersion !== '0.
|
|
329
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
328
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
329
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
330
330
|
}
|
|
331
331
|
return binding
|
|
332
332
|
} catch (e) {
|
|
@@ -341,8 +341,42 @@ function requireNative() {
|
|
|
341
341
|
try {
|
|
342
342
|
const binding = require('@tursodatabase/database-linux-arm-gnueabihf')
|
|
343
343
|
const bindingPackageVersion = require('@tursodatabase/database-linux-arm-gnueabihf/package.json').version
|
|
344
|
-
if (bindingPackageVersion !== '0.
|
|
345
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
344
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
345
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
346
|
+
}
|
|
347
|
+
return binding
|
|
348
|
+
} catch (e) {
|
|
349
|
+
loadErrors.push(e)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
} else if (process.arch === 'loong64') {
|
|
353
|
+
if (isMusl()) {
|
|
354
|
+
try {
|
|
355
|
+
return require('./turso.linux-loong64-musl.node')
|
|
356
|
+
} catch (e) {
|
|
357
|
+
loadErrors.push(e)
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
const binding = require('@tursodatabase/database-linux-loong64-musl')
|
|
361
|
+
const bindingPackageVersion = require('@tursodatabase/database-linux-loong64-musl/package.json').version
|
|
362
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
363
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
364
|
+
}
|
|
365
|
+
return binding
|
|
366
|
+
} catch (e) {
|
|
367
|
+
loadErrors.push(e)
|
|
368
|
+
}
|
|
369
|
+
} else {
|
|
370
|
+
try {
|
|
371
|
+
return require('./turso.linux-loong64-gnu.node')
|
|
372
|
+
} catch (e) {
|
|
373
|
+
loadErrors.push(e)
|
|
374
|
+
}
|
|
375
|
+
try {
|
|
376
|
+
const binding = require('@tursodatabase/database-linux-loong64-gnu')
|
|
377
|
+
const bindingPackageVersion = require('@tursodatabase/database-linux-loong64-gnu/package.json').version
|
|
378
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
379
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
346
380
|
}
|
|
347
381
|
return binding
|
|
348
382
|
} catch (e) {
|
|
@@ -359,8 +393,8 @@ function requireNative() {
|
|
|
359
393
|
try {
|
|
360
394
|
const binding = require('@tursodatabase/database-linux-riscv64-musl')
|
|
361
395
|
const bindingPackageVersion = require('@tursodatabase/database-linux-riscv64-musl/package.json').version
|
|
362
|
-
if (bindingPackageVersion !== '0.
|
|
363
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
396
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
397
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
364
398
|
}
|
|
365
399
|
return binding
|
|
366
400
|
} catch (e) {
|
|
@@ -375,8 +409,8 @@ function requireNative() {
|
|
|
375
409
|
try {
|
|
376
410
|
const binding = require('@tursodatabase/database-linux-riscv64-gnu')
|
|
377
411
|
const bindingPackageVersion = require('@tursodatabase/database-linux-riscv64-gnu/package.json').version
|
|
378
|
-
if (bindingPackageVersion !== '0.
|
|
379
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
412
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
413
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
380
414
|
}
|
|
381
415
|
return binding
|
|
382
416
|
} catch (e) {
|
|
@@ -392,8 +426,8 @@ function requireNative() {
|
|
|
392
426
|
try {
|
|
393
427
|
const binding = require('@tursodatabase/database-linux-ppc64-gnu')
|
|
394
428
|
const bindingPackageVersion = require('@tursodatabase/database-linux-ppc64-gnu/package.json').version
|
|
395
|
-
if (bindingPackageVersion !== '0.
|
|
396
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
429
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
430
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
397
431
|
}
|
|
398
432
|
return binding
|
|
399
433
|
} catch (e) {
|
|
@@ -408,8 +442,8 @@ function requireNative() {
|
|
|
408
442
|
try {
|
|
409
443
|
const binding = require('@tursodatabase/database-linux-s390x-gnu')
|
|
410
444
|
const bindingPackageVersion = require('@tursodatabase/database-linux-s390x-gnu/package.json').version
|
|
411
|
-
if (bindingPackageVersion !== '0.
|
|
412
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
445
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
446
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
413
447
|
}
|
|
414
448
|
return binding
|
|
415
449
|
} catch (e) {
|
|
@@ -428,8 +462,8 @@ function requireNative() {
|
|
|
428
462
|
try {
|
|
429
463
|
const binding = require('@tursodatabase/database-openharmony-arm64')
|
|
430
464
|
const bindingPackageVersion = require('@tursodatabase/database-openharmony-arm64/package.json').version
|
|
431
|
-
if (bindingPackageVersion !== '0.
|
|
432
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
465
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
466
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
433
467
|
}
|
|
434
468
|
return binding
|
|
435
469
|
} catch (e) {
|
|
@@ -444,8 +478,8 @@ function requireNative() {
|
|
|
444
478
|
try {
|
|
445
479
|
const binding = require('@tursodatabase/database-openharmony-x64')
|
|
446
480
|
const bindingPackageVersion = require('@tursodatabase/database-openharmony-x64/package.json').version
|
|
447
|
-
if (bindingPackageVersion !== '0.
|
|
448
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
481
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
482
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
449
483
|
}
|
|
450
484
|
return binding
|
|
451
485
|
} catch (e) {
|
|
@@ -460,8 +494,8 @@ function requireNative() {
|
|
|
460
494
|
try {
|
|
461
495
|
const binding = require('@tursodatabase/database-openharmony-arm')
|
|
462
496
|
const bindingPackageVersion = require('@tursodatabase/database-openharmony-arm/package.json').version
|
|
463
|
-
if (bindingPackageVersion !== '0.
|
|
464
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
497
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
498
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
465
499
|
}
|
|
466
500
|
return binding
|
|
467
501
|
} catch (e) {
|
|
@@ -478,22 +512,32 @@ function requireNative() {
|
|
|
478
512
|
nativeBinding = requireNative()
|
|
479
513
|
|
|
480
514
|
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
515
|
+
let wasiBinding = null
|
|
516
|
+
let wasiBindingError = null
|
|
481
517
|
try {
|
|
482
|
-
|
|
518
|
+
wasiBinding = require('./turso.wasi.cjs')
|
|
519
|
+
nativeBinding = wasiBinding
|
|
483
520
|
} catch (err) {
|
|
484
521
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
485
|
-
|
|
522
|
+
wasiBindingError = err
|
|
486
523
|
}
|
|
487
524
|
}
|
|
488
525
|
if (!nativeBinding) {
|
|
489
526
|
try {
|
|
490
|
-
|
|
527
|
+
wasiBinding = require('@tursodatabase/database-wasm32-wasi')
|
|
528
|
+
nativeBinding = wasiBinding
|
|
491
529
|
} catch (err) {
|
|
492
530
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
531
|
+
wasiBindingError.cause = err
|
|
493
532
|
loadErrors.push(err)
|
|
494
533
|
}
|
|
495
534
|
}
|
|
496
535
|
}
|
|
536
|
+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
537
|
+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
538
|
+
error.cause = wasiBindingError
|
|
539
|
+
throw error
|
|
540
|
+
}
|
|
497
541
|
}
|
|
498
542
|
|
|
499
543
|
if (!nativeBinding) {
|
|
@@ -502,12 +546,18 @@ if (!nativeBinding) {
|
|
|
502
546
|
`Cannot find native binding. ` +
|
|
503
547
|
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
504
548
|
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
505
|
-
{
|
|
549
|
+
{
|
|
550
|
+
cause: loadErrors.reduce((err, cur) => {
|
|
551
|
+
cur.cause = err
|
|
552
|
+
return cur
|
|
553
|
+
}),
|
|
554
|
+
},
|
|
506
555
|
)
|
|
507
556
|
}
|
|
508
557
|
throw new Error(`Failed to load native binding`)
|
|
509
558
|
}
|
|
510
559
|
|
|
511
|
-
const { Database, Statement } = nativeBinding
|
|
560
|
+
const { BatchExecutor, Database, Statement } = nativeBinding
|
|
561
|
+
export { BatchExecutor }
|
|
512
562
|
export { Database }
|
|
513
563
|
export { Statement }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tursodatabase/database",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.11",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/tursodatabase/turso"
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@napi-rs/cli": "^3.1.5",
|
|
24
24
|
"@types/node": "^24.3.1",
|
|
25
|
+
"better-sqlite3": "^12.2.0",
|
|
26
|
+
"drizzle-kit": "^0.31.4",
|
|
27
|
+
"drizzle-orm": "^0.44.5",
|
|
25
28
|
"typescript": "^5.9.2",
|
|
26
29
|
"vitest": "^3.2.4"
|
|
27
30
|
},
|
|
@@ -39,20 +42,20 @@
|
|
|
39
42
|
"targets": [
|
|
40
43
|
"x86_64-unknown-linux-gnu",
|
|
41
44
|
"x86_64-pc-windows-msvc",
|
|
42
|
-
"
|
|
45
|
+
"aarch64-apple-darwin",
|
|
43
46
|
"aarch64-unknown-linux-gnu"
|
|
44
47
|
]
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
|
-
"@tursodatabase/database-common": "^0.2.0-pre.
|
|
50
|
+
"@tursodatabase/database-common": "^0.2.0-pre.11"
|
|
48
51
|
},
|
|
49
52
|
"imports": {
|
|
50
53
|
"#index": "./index.js"
|
|
51
54
|
},
|
|
52
55
|
"optionalDependencies": {
|
|
53
|
-
"@tursodatabase/database-linux-x64-gnu": "0.2.0-pre.
|
|
54
|
-
"@tursodatabase/database-win32-x64-msvc": "0.2.0-pre.
|
|
55
|
-
"@tursodatabase/database-darwin-
|
|
56
|
-
"@tursodatabase/database-linux-arm64-gnu": "0.2.0-pre.
|
|
56
|
+
"@tursodatabase/database-linux-x64-gnu": "0.2.0-pre.11",
|
|
57
|
+
"@tursodatabase/database-win32-x64-msvc": "0.2.0-pre.11",
|
|
58
|
+
"@tursodatabase/database-darwin-arm64": "0.2.0-pre.11",
|
|
59
|
+
"@tursodatabase/database-linux-arm64-gnu": "0.2.0-pre.11"
|
|
57
60
|
}
|
|
58
61
|
}
|