@tursodatabase/database 0.9.0-pre.6 → 0.9.0-pre.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compat.test.js +8 -7
- package/dist/promise.test.js +45 -26
- package/package.json +7 -7
package/dist/compat.test.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { unlinkSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { expect, test } from 'vitest';
|
|
3
4
|
import { Database, SqliteError } from './compat.js';
|
|
@@ -33,7 +34,7 @@ test('errors carry the SQLite message and result code name', () => {
|
|
|
33
34
|
db.exec('CREATE TABLE s(a INTEGER) STRICT');
|
|
34
35
|
db.exec('CREATE TABLE tr(a)');
|
|
35
36
|
db.exec("CREATE TRIGGER trg BEFORE INSERT ON tr BEGIN SELECT RAISE(ABORT, 'nope'); END");
|
|
36
|
-
const notADatabase = `test-${(
|
|
37
|
+
const notADatabase = `test-${randomUUID()}.db`;
|
|
37
38
|
writeFileSync(notADatabase, Buffer.alloc(8192, 7));
|
|
38
39
|
const cases = [
|
|
39
40
|
[() => db.prepare('INSERT INTO t(a) VALUES (1)').run(), 'SQLITE_CONSTRAINT_UNIQUE', 'UNIQUE constraint failed: t.a'],
|
|
@@ -104,7 +105,7 @@ test('expanded rows collapse duplicate column names like better-sqlite3', () =>
|
|
|
104
105
|
expect(stmt.raw(true).get()).toEqual(["/Employee", "/"]);
|
|
105
106
|
});
|
|
106
107
|
test('readonly-db', () => {
|
|
107
|
-
const path = `test-${(
|
|
108
|
+
const path = `test-${randomUUID()}.db`;
|
|
108
109
|
try {
|
|
109
110
|
{
|
|
110
111
|
const rw = new Database(path);
|
|
@@ -125,7 +126,7 @@ test('readonly-db', () => {
|
|
|
125
126
|
}
|
|
126
127
|
});
|
|
127
128
|
test('file-must-exist', () => {
|
|
128
|
-
const path = `test-${(
|
|
129
|
+
const path = `test-${randomUUID()}.db`;
|
|
129
130
|
let error;
|
|
130
131
|
try {
|
|
131
132
|
new Database(path, { fileMustExist: true });
|
|
@@ -138,7 +139,7 @@ test('file-must-exist', () => {
|
|
|
138
139
|
expect(error.message).toContain('I/O error (open)');
|
|
139
140
|
});
|
|
140
141
|
test('on-disk db', () => {
|
|
141
|
-
const path = `test-${(
|
|
142
|
+
const path = `test-${randomUUID()}.db`;
|
|
142
143
|
try {
|
|
143
144
|
const db1 = new Database(path);
|
|
144
145
|
db1.exec("CREATE TABLE t(x)");
|
|
@@ -161,8 +162,8 @@ test('on-disk db', () => {
|
|
|
161
162
|
}
|
|
162
163
|
});
|
|
163
164
|
test('attach', () => {
|
|
164
|
-
const path1 = `test-${(
|
|
165
|
-
const path2 = `test-${(
|
|
165
|
+
const path1 = `test-${randomUUID()}.db`;
|
|
166
|
+
const path2 = `test-${randomUUID()}.db`;
|
|
166
167
|
try {
|
|
167
168
|
const db1 = new Database(path1, { experimental: ["attach"] });
|
|
168
169
|
db1.exec("CREATE TABLE t(x)");
|
|
@@ -189,7 +190,7 @@ test('blobs', () => {
|
|
|
189
190
|
expect(rows).toEqual([{ x: Buffer.from([16, 32]) }]);
|
|
190
191
|
});
|
|
191
192
|
test('encryption', () => {
|
|
192
|
-
const path = `test-encryption-${(
|
|
193
|
+
const path = `test-encryption-${randomUUID()}.db`;
|
|
193
194
|
const hexkey = 'b1bbfda4f589dc9daaf004fe21111e00dc00c98237102f5c7002a5669fc76327';
|
|
194
195
|
const wrongKey = 'aaaaaaa4f589dc9daaf004fe21111e00dc00c98237102f5c7002a5669fc76327';
|
|
195
196
|
try {
|
package/dist/promise.test.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { unlinkSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { expect, test } from 'vitest';
|
|
3
4
|
import { Database, connect, SqliteError, Transaction } from './promise.js';
|
|
4
5
|
import { sql } from 'drizzle-orm';
|
|
5
6
|
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
6
7
|
test('drizzle-orm', async () => {
|
|
7
|
-
const path = `test-${(
|
|
8
|
+
const path = `test-${randomUUID()}.db`;
|
|
8
9
|
try {
|
|
9
10
|
const conn = await connect(path);
|
|
10
11
|
const db = drizzle(conn);
|
|
@@ -54,7 +55,7 @@ test('concurrent calls on one prepared statement use their own parameters', asyn
|
|
|
54
55
|
expect(await db.all("SELECT k FROM w ORDER BY k")).toEqual([{ k: 'a' }, { k: 'b' }]);
|
|
55
56
|
});
|
|
56
57
|
test('busy timeout gives up on time when the write lock is never released', async () => {
|
|
57
|
-
const path = `test-${(
|
|
58
|
+
const path = `test-${randomUUID()}.db`;
|
|
58
59
|
try {
|
|
59
60
|
const conn1 = await connect(path);
|
|
60
61
|
await conn1.exec("CREATE TABLE t(x)");
|
|
@@ -78,7 +79,7 @@ test('busy timeout gives up on time when the write lock is never released', asyn
|
|
|
78
79
|
}
|
|
79
80
|
});
|
|
80
81
|
test('busy timeout sleeps instead of blocking the event loop', async () => {
|
|
81
|
-
const path = `test-${(
|
|
82
|
+
const path = `test-${randomUUID()}.db`;
|
|
82
83
|
try {
|
|
83
84
|
const conn1 = await connect(path);
|
|
84
85
|
await conn1.exec("CREATE TABLE t(x)");
|
|
@@ -121,7 +122,7 @@ test('expanded rows collapse duplicate column names like better-sqlite3', async
|
|
|
121
122
|
expect(await stmt.raw(true).get()).toEqual(["/Employee", "/"]);
|
|
122
123
|
});
|
|
123
124
|
test('readonly-db', async () => {
|
|
124
|
-
const path = `test-${(
|
|
125
|
+
const path = `test-${randomUUID()}.db`;
|
|
125
126
|
try {
|
|
126
127
|
{
|
|
127
128
|
const rw = await connect(path);
|
|
@@ -142,7 +143,7 @@ test('readonly-db', async () => {
|
|
|
142
143
|
}
|
|
143
144
|
});
|
|
144
145
|
test('file-must-exist', async () => {
|
|
145
|
-
const path = `test-${(
|
|
146
|
+
const path = `test-${randomUUID()}.db`;
|
|
146
147
|
const error = await connect(path, { fileMustExist: true }).then(() => undefined, (e) => e);
|
|
147
148
|
expect(error).toBeInstanceOf(SqliteError);
|
|
148
149
|
expect(error.code).toBe('SQLITE_CANTOPEN');
|
|
@@ -156,7 +157,7 @@ test('implicit connect', async () => {
|
|
|
156
157
|
expect(await (await db.prepare("SELECT 1 as x")).all()).toEqual([{ x: 1 }]);
|
|
157
158
|
});
|
|
158
159
|
test('errors carry the SQLite message and result code name', async () => {
|
|
159
|
-
const notADatabase = `test-${(
|
|
160
|
+
const notADatabase = `test-${randomUUID()}.db`;
|
|
160
161
|
writeFileSync(notADatabase, Buffer.alloc(8192, 7));
|
|
161
162
|
const db = await connect(':memory:');
|
|
162
163
|
await db.exec('PRAGMA foreign_keys = ON');
|
|
@@ -280,7 +281,7 @@ test('columns() gives each column its origin and declared type, as in better-sql
|
|
|
280
281
|
]);
|
|
281
282
|
});
|
|
282
283
|
test('on-disk db', async () => {
|
|
283
|
-
const path = `test-${(
|
|
284
|
+
const path = `test-${randomUUID()}.db`;
|
|
284
285
|
try {
|
|
285
286
|
const db1 = await connect(path);
|
|
286
287
|
await db1.exec("CREATE TABLE t(x)");
|
|
@@ -303,8 +304,8 @@ test('on-disk db', async () => {
|
|
|
303
304
|
}
|
|
304
305
|
});
|
|
305
306
|
test('attach', async () => {
|
|
306
|
-
const path1 = `test-${(
|
|
307
|
-
const path2 = `test-${(
|
|
307
|
+
const path1 = `test-${randomUUID()}.db`;
|
|
308
|
+
const path2 = `test-${randomUUID()}.db`;
|
|
308
309
|
try {
|
|
309
310
|
const db1 = await connect(path1, { experimental: ["attach"] });
|
|
310
311
|
await db1.exec("CREATE TABLE t(x)");
|
|
@@ -357,7 +358,7 @@ test('blobs', async () => {
|
|
|
357
358
|
expect(rows).toEqual([{ x: Buffer.from([16, 32]) }]);
|
|
358
359
|
});
|
|
359
360
|
test('encryption', async () => {
|
|
360
|
-
const path = `test-encryption-${(
|
|
361
|
+
const path = `test-encryption-${randomUUID()}.db`;
|
|
361
362
|
const hexkey = 'b1bbfda4f589dc9daaf004fe21111e00dc00c98237102f5c7002a5669fc76327';
|
|
362
363
|
const wrongKey = 'aaaaaaa4f589dc9daaf004fe21111e00dc00c98237102f5c7002a5669fc76327';
|
|
363
364
|
try {
|
|
@@ -617,24 +618,31 @@ test('batch validates every bigint before executing the first statement', async
|
|
|
617
618
|
const stmt = await db.prepare("SELECT COUNT(*) AS n FROM t_batch_bigint_validation");
|
|
618
619
|
expect(await stmt.all([])).toEqual([{ n: 0 }]);
|
|
619
620
|
});
|
|
620
|
-
test('batch
|
|
621
|
+
test('batch refuses a value with no SQLite type before executing the first statement', async () => {
|
|
621
622
|
const db = await connect(":memory:");
|
|
622
|
-
await db.exec("CREATE TABLE
|
|
623
|
-
let
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
623
|
+
await db.exec("CREATE TABLE t_batch_unbindable (x)");
|
|
624
|
+
let error;
|
|
625
|
+
try {
|
|
626
|
+
await db.batch([
|
|
627
|
+
{ sql: "INSERT INTO t_batch_unbindable VALUES (?)", args: [1] },
|
|
628
|
+
{ sql: "INSERT INTO t_batch_unbindable VALUES (?)", args: [new Date(0)] },
|
|
629
|
+
]);
|
|
630
|
+
}
|
|
631
|
+
catch (caught) {
|
|
632
|
+
error = caught;
|
|
633
|
+
}
|
|
634
|
+
expect(error).toBeInstanceOf(TypeError);
|
|
635
|
+
expect(error.message).toContain("SQLite3 can only bind numbers, strings, bigints, buffers, and null");
|
|
636
|
+
expect(error.batchIndex).toBe(1);
|
|
637
|
+
const stmt = await db.prepare("SELECT COUNT(*) AS n FROM t_batch_unbindable");
|
|
638
|
+
expect(await stmt.all([])).toEqual([{ n: 0 }]);
|
|
639
|
+
});
|
|
640
|
+
test('batch binds a DataView as its bytes', async () => {
|
|
641
|
+
const db = await connect(":memory:");
|
|
642
|
+
const [result] = await db.batch([
|
|
643
|
+
{ sql: "SELECT hex(?) AS x", args: [new DataView(new Uint8Array([9, 1, 2, 3]).buffer, 1, 2)] },
|
|
634
644
|
]);
|
|
635
|
-
expect(
|
|
636
|
-
const stmt = await db.prepare("SELECT x FROM t_batch_coercion");
|
|
637
|
-
expect(await stmt.all([])).toEqual([{ x: "coerced" }]);
|
|
645
|
+
expect(result.rows).toEqual([{ x: "0102" }]);
|
|
638
646
|
});
|
|
639
647
|
test('atomic batch rejects transaction control before BEGIN', async () => {
|
|
640
648
|
const db = await connect(":memory:");
|
|
@@ -697,3 +705,14 @@ test('a whole number binds as INTEGER only inside the int64 range', async () =>
|
|
|
697
705
|
expect(await stmt.get(2 ** 63 - 1024)).toEqual({ type: "integer", above_max: 0 });
|
|
698
706
|
expect(await stmt.get(-(2 ** 63))).toEqual({ type: "integer", above_max: 0 });
|
|
699
707
|
});
|
|
708
|
+
test('undefined binds as NULL and a value with no SQLite type is refused', async () => {
|
|
709
|
+
const db = await connect(":memory:");
|
|
710
|
+
const stmt = await db.prepare("SELECT typeof(?) AS a, typeof(?) AS b");
|
|
711
|
+
expect(await stmt.get(1, undefined)).toEqual({ a: "integer", b: "null" });
|
|
712
|
+
expect(await stmt.get([undefined, 1])).toEqual({ a: "null", b: "integer" });
|
|
713
|
+
for (const value of [new Date(0), { a: 1 }, new Map(), new ArrayBuffer(2), () => 1, Symbol("s")]) {
|
|
714
|
+
const error = await stmt.get(1, value).catch((e) => e);
|
|
715
|
+
expect(error).toBeInstanceOf(TypeError);
|
|
716
|
+
expect(error.message).toBe("SQLite3 can only bind numbers, strings, bigints, buffers, and null");
|
|
717
|
+
}
|
|
718
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tursodatabase/database",
|
|
3
|
-
"version": "0.9.0-pre.
|
|
3
|
+
"version": "0.9.0-pre.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/tursodatabase/turso"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"drizzle-kit": "^0.31.4",
|
|
27
27
|
"drizzle-orm": "^0.45.2",
|
|
28
28
|
"typescript": "^5.9.2",
|
|
29
|
-
"vitest": "^4.1.
|
|
29
|
+
"vitest": "^4.1.12"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"napi-build": "napi build --platform --profile release-official --esm --manifest-path ../../Cargo.toml --output-dir .",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
]
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@tursodatabase/database-common": "^0.9.0-pre.
|
|
52
|
+
"@tursodatabase/database-common": "^0.9.0-pre.7"
|
|
53
53
|
},
|
|
54
54
|
"imports": {
|
|
55
55
|
"#index": "./index.js"
|
|
56
56
|
},
|
|
57
57
|
"optionalDependencies": {
|
|
58
|
-
"@tursodatabase/database-linux-x64-gnu": "0.9.0-pre.
|
|
59
|
-
"@tursodatabase/database-win32-x64-msvc": "0.9.0-pre.
|
|
60
|
-
"@tursodatabase/database-darwin-arm64": "0.9.0-pre.
|
|
61
|
-
"@tursodatabase/database-linux-arm64-gnu": "0.9.0-pre.
|
|
58
|
+
"@tursodatabase/database-linux-x64-gnu": "0.9.0-pre.7",
|
|
59
|
+
"@tursodatabase/database-win32-x64-msvc": "0.9.0-pre.7",
|
|
60
|
+
"@tursodatabase/database-darwin-arm64": "0.9.0-pre.7",
|
|
61
|
+
"@tursodatabase/database-linux-arm64-gnu": "0.9.0-pre.7"
|
|
62
62
|
}
|
|
63
63
|
}
|