mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 01:58:16 +00:00
bind/js: Add proper exec() method
This commit is contained in:
parent
482eb4aa9a
commit
1367b453e9
4 changed files with 72 additions and 2 deletions
|
@ -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 "../wrapper.js";
|
||||
|
||||
|
@ -103,6 +106,20 @@ test("Test pluck(): Rows should only have the values of the first column", async
|
|||
}
|
||||
});
|
||||
|
||||
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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue