bind/js: Add proper exec() method

This commit is contained in:
Diego Reis
2025-05-29 15:59:07 -03:00
parent 482eb4aa9a
commit 1367b453e9
4 changed files with 72 additions and 2 deletions

View File

@@ -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];