mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-09 03:04:20 +01:00
bind/js: Add proper exec() method
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import test from "ava";
|
||||
import fs from "node:fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import path from "node:path"
|
||||
|
||||
import Database from "better-sqlite3";
|
||||
|
||||
@@ -77,6 +80,21 @@ test("Test bind()", async (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
test("Test exec()", async (t) => {
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const [db] = await connect(":memory:");
|
||||
const file = fs.readFileSync(path.resolve(__dirname, "./artifacts/basic-test.sql"), "utf8");
|
||||
db.exec(file);
|
||||
let rows = db.prepare("SELECT * FROM users").iterate();
|
||||
for (const row of rows) {
|
||||
t.truthy(row.name);
|
||||
t.true(typeof row.age === "number");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const connect = async (path) => {
|
||||
const db = new Database(path);
|
||||
return [db];
|
||||
|
||||
Reference in New Issue
Block a user