mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 08:55:40 +01:00
fix exec to run over multiple statements in the string
This commit is contained in:
@@ -11,6 +11,14 @@ test('in-memory db', () => {
|
||||
expect(rows).toEqual([{ x: 1 }, { x: 3 }]);
|
||||
})
|
||||
|
||||
test('exec multiple statements', async () => {
|
||||
const db = new Database(":memory:");
|
||||
db.exec("CREATE TABLE t(x); INSERT INTO t VALUES (1); INSERT INTO t VALUES (2)");
|
||||
const stmt = db.prepare("SELECT * FROM t");
|
||||
const rows = stmt.all();
|
||||
expect(rows).toEqual([{ x: 1 }, { x: 2 }]);
|
||||
})
|
||||
|
||||
test('readonly-db', () => {
|
||||
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
/* auto-generated by NAPI-RS */
|
||||
/* eslint-disable */
|
||||
export declare class BatchExecutor {
|
||||
stepSync(): number
|
||||
reset(): void
|
||||
}
|
||||
|
||||
/** A database connection. */
|
||||
export declare class Database {
|
||||
/**
|
||||
@@ -39,6 +44,7 @@ export declare class Database {
|
||||
* A `Statement` instance.
|
||||
*/
|
||||
prepare(sql: string): Statement
|
||||
executor(sql: string): BatchExecutor
|
||||
/**
|
||||
* Returns the rowid of the last row inserted.
|
||||
*
|
||||
|
||||
@@ -508,6 +508,7 @@ if (!nativeBinding) {
|
||||
throw new Error(`Failed to load native binding`)
|
||||
}
|
||||
|
||||
const { Database, Statement } = nativeBinding
|
||||
const { BatchExecutor, Database, Statement } = nativeBinding
|
||||
export { BatchExecutor }
|
||||
export { Database }
|
||||
export { Statement }
|
||||
|
||||
@@ -31,6 +31,14 @@ test('in-memory-db-async', async () => {
|
||||
expect(rows).toEqual([{ x: 1 }, { x: 3 }]);
|
||||
})
|
||||
|
||||
test('exec multiple statements', async () => {
|
||||
const db = await connect(":memory:");
|
||||
await db.exec("CREATE TABLE t(x); INSERT INTO t VALUES (1); INSERT INTO t VALUES (2)");
|
||||
const stmt = db.prepare("SELECT * FROM t");
|
||||
const rows = await stmt.all();
|
||||
expect(rows).toEqual([{ x: 1 }, { x: 2 }]);
|
||||
})
|
||||
|
||||
test('readonly-db', async () => {
|
||||
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user