@tursodatabase/database 0.9.0-pre.4 → 0.9.0-pre.6

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.
@@ -144,13 +144,13 @@ test('on-disk db', () => {
144
144
  db1.exec("CREATE TABLE t(x)");
145
145
  db1.exec("INSERT INTO t VALUES (1), (2), (3)");
146
146
  const stmt1 = db1.prepare("SELECT * FROM t WHERE x % 2 = ?");
147
- expect(stmt1.columns()).toEqual([{ name: "x", column: null, database: null, table: null, type: null }]);
147
+ expect(stmt1.columns()).toEqual([{ name: "x", column: "x", database: "main", table: "t", type: null }]);
148
148
  const rows1 = stmt1.all([1]);
149
149
  expect(rows1).toEqual([{ x: 1 }, { x: 3 }]);
150
150
  db1.close();
151
151
  const db2 = new Database(path);
152
152
  const stmt2 = db2.prepare("SELECT * FROM t WHERE x % 2 = ?");
153
- expect(stmt2.columns()).toEqual([{ name: "x", column: null, database: null, table: null, type: null }]);
153
+ expect(stmt2.columns()).toEqual([{ name: "x", column: "x", database: "main", table: "t", type: null }]);
154
154
  const rows2 = stmt2.all([1]);
155
155
  expect(rows2).toEqual([{ x: 1 }, { x: 3 }]);
156
156
  db2.close();
@@ -172,7 +172,7 @@ test('attach', () => {
172
172
  db2.exec("INSERT INTO q VALUES (4), (5), (6)");
173
173
  db1.exec(`ATTACH '${path2}' as secondary`);
174
174
  const stmt = db1.prepare("SELECT * FROM t UNION ALL SELECT * FROM secondary.q");
175
- expect(stmt.columns()).toEqual([{ name: "x", column: null, database: null, table: null, type: null }]);
175
+ expect(stmt.columns()).toEqual([{ name: "x", column: "x", database: "main", table: "t", type: null }]);
176
176
  const rows = stmt.all([1]);
177
177
  expect(rows).toEqual([{ x: 1 }, { x: 2 }, { x: 3 }, { x: 4 }, { x: 5 }, { x: 6 }]);
178
178
  }
@@ -224,3 +224,60 @@ test('encryption', () => {
224
224
  unlinkSync(path);
225
225
  }
226
226
  });
227
+ test('a transaction function called inside another runs as a savepoint, as in better-sqlite3', () => {
228
+ const db = new Database(':memory:');
229
+ db.exec('CREATE TABLE t (x INTEGER)');
230
+ const insert = db.prepare('INSERT INTO t VALUES (?)');
231
+ const inner = db.transaction((x) => {
232
+ insert.run(x);
233
+ if (x === 2)
234
+ throw new Error('inner failed');
235
+ });
236
+ const outer = db.transaction(() => {
237
+ inner(1);
238
+ expect(() => inner(2)).toThrow('inner failed');
239
+ insert.run(3);
240
+ });
241
+ outer();
242
+ expect(db.prepare('SELECT x FROM t ORDER BY x').all()).toEqual([{ x: 1 }, { x: 3 }]);
243
+ });
244
+ test('transaction functions nest three deep, each level rolling back only itself', () => {
245
+ const db = new Database(':memory:');
246
+ db.exec('CREATE TABLE t (x INTEGER)');
247
+ const insert = db.prepare('INSERT INTO t VALUES (?)');
248
+ const inner = db.transaction((x) => {
249
+ insert.run(x);
250
+ throw new Error('inner failed');
251
+ });
252
+ const middle = db.transaction(() => {
253
+ insert.run(2);
254
+ expect(() => inner(3)).toThrow('inner failed');
255
+ insert.run(4);
256
+ });
257
+ const outer = db.transaction(() => {
258
+ insert.run(1);
259
+ middle();
260
+ insert.run(5);
261
+ });
262
+ outer();
263
+ expect(db.inTransaction).toBe(false);
264
+ expect(db.prepare('SELECT x FROM t ORDER BY x').all()).toEqual([{ x: 1 }, { x: 2 }, { x: 4 }, { x: 5 }]);
265
+ });
266
+ test('an error that leaves every nested transaction function rolls back the whole transaction', () => {
267
+ const db = new Database(':memory:');
268
+ db.exec('CREATE TABLE t (x INTEGER)');
269
+ const insert = db.prepare('INSERT INTO t VALUES (?)');
270
+ const inner = db.transaction((x) => {
271
+ insert.run(x);
272
+ throw new Error('inner failed');
273
+ });
274
+ const outer = db.transaction(() => {
275
+ insert.run(1);
276
+ inner(2);
277
+ });
278
+ expect(() => outer()).toThrow('inner failed');
279
+ expect(db.inTransaction).toBe(false);
280
+ expect(db.prepare('SELECT x FROM t').all()).toEqual([]);
281
+ db.transaction(() => insert.run(3))();
282
+ expect(db.prepare('SELECT x FROM t').all()).toEqual([{ x: 3 }]);
283
+ });
@@ -268,6 +268,17 @@ test('conflict-bug', async () => {
268
268
  { id: 2, name: 'John Second', email: '2john@example.com' }
269
269
  ]);
270
270
  });
271
+ test('columns() gives each column its origin and declared type, as in better-sqlite3', async () => {
272
+ const db = await connect(":memory:");
273
+ await db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, created BIGINT NOT NULL, name VARCHAR(40))");
274
+ const stmt = await db.prepare("SELECT id, created, name AS display, id + 1 AS next FROM users");
275
+ expect(stmt.columns()).toEqual([
276
+ { name: "id", column: "id", table: "users", database: "main", type: "INTEGER" },
277
+ { name: "created", column: "created", table: "users", database: "main", type: "BIGINT" },
278
+ { name: "display", column: "name", table: "users", database: "main", type: "VARCHAR(40)" },
279
+ { name: "next", column: null, table: null, database: null, type: null },
280
+ ]);
281
+ });
271
282
  test('on-disk db', async () => {
272
283
  const path = `test-${(Math.random() * 10000) | 0}.db`;
273
284
  try {
@@ -275,13 +286,13 @@ test('on-disk db', async () => {
275
286
  await db1.exec("CREATE TABLE t(x)");
276
287
  await db1.exec("INSERT INTO t VALUES (1), (2), (3)");
277
288
  const stmt1 = await db1.prepare("SELECT * FROM t WHERE x % 2 = ?");
278
- expect(stmt1.columns()).toEqual([{ name: "x", column: null, database: null, table: null, type: null }]);
289
+ expect(stmt1.columns()).toEqual([{ name: "x", column: "x", database: "main", table: "t", type: null }]);
279
290
  const rows1 = await stmt1.all([1]);
280
291
  expect(rows1).toEqual([{ x: 1 }, { x: 3 }]);
281
292
  db1.close();
282
293
  const db2 = await connect(path);
283
294
  const stmt2 = await db2.prepare("SELECT * FROM t WHERE x % 2 = ?");
284
- expect(stmt2.columns()).toEqual([{ name: "x", column: null, database: null, table: null, type: null }]);
295
+ expect(stmt2.columns()).toEqual([{ name: "x", column: "x", database: "main", table: "t", type: null }]);
285
296
  const rows2 = await stmt2.all([1]);
286
297
  expect(rows2).toEqual([{ x: 1 }, { x: 3 }]);
287
298
  db2.close();
@@ -303,7 +314,7 @@ test('attach', async () => {
303
314
  await db2.exec("INSERT INTO q VALUES (4), (5), (6)");
304
315
  await db1.exec(`ATTACH '${path2}' as secondary`);
305
316
  const stmt = await db1.prepare("SELECT * FROM t UNION ALL SELECT * FROM secondary.q");
306
- expect(stmt.columns()).toEqual([{ name: "x", column: null, database: null, table: null, type: null }]);
317
+ expect(stmt.columns()).toEqual([{ name: "x", column: "x", database: "main", table: "t", type: null }]);
307
318
  const rows = await stmt.all([1]);
308
319
  expect(rows).toEqual([{ x: 1 }, { x: 2 }, { x: 3 }, { x: 4 }, { x: 5 }, { x: 6 }]);
309
320
  }
@@ -678,3 +689,11 @@ test('atomic batch attaches a rollback failure to the primary error', async () =
678
689
  expect(error.rollbackError).toBeInstanceOf(Error);
679
690
  expect(error.rollbackError.message).toBe("rollback failed");
680
691
  });
692
+ test('a whole number binds as INTEGER only inside the int64 range', async () => {
693
+ const db = await connect(":memory:");
694
+ const stmt = await db.prepare("SELECT typeof(?1) AS type, ?1 > 9223372036854775807 AS above_max");
695
+ expect(await stmt.get(2 ** 63)).toEqual({ type: "real", above_max: 1 });
696
+ expect(await stmt.get(2 ** 64)).toEqual({ type: "real", above_max: 1 });
697
+ expect(await stmt.get(2 ** 63 - 1024)).toEqual({ type: "integer", above_max: 0 });
698
+ expect(await stmt.get(-(2 ** 63))).toEqual({ type: "integer", above_max: 0 });
699
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tursodatabase/database",
3
- "version": "0.9.0-pre.4",
3
+ "version": "0.9.0-pre.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/tursodatabase/turso"
@@ -49,15 +49,15 @@
49
49
  ]
50
50
  },
51
51
  "dependencies": {
52
- "@tursodatabase/database-common": "^0.9.0-pre.4"
52
+ "@tursodatabase/database-common": "^0.9.0-pre.6"
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.4",
59
- "@tursodatabase/database-win32-x64-msvc": "0.9.0-pre.4",
60
- "@tursodatabase/database-darwin-arm64": "0.9.0-pre.4",
61
- "@tursodatabase/database-linux-arm64-gnu": "0.9.0-pre.4"
58
+ "@tursodatabase/database-linux-x64-gnu": "0.9.0-pre.6",
59
+ "@tursodatabase/database-win32-x64-msvc": "0.9.0-pre.6",
60
+ "@tursodatabase/database-darwin-arm64": "0.9.0-pre.6",
61
+ "@tursodatabase/database-linux-arm64-gnu": "0.9.0-pre.6"
62
62
  }
63
63
  }