mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-09 10:14:21 +01:00
bind/js: Add proper exec() method
This commit is contained in:
3
bindings/javascript/__test__/artifacts/basic-test.sql
Normal file
3
bindings/javascript/__test__/artifacts/basic-test.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
CREATE TABLE users (name TEXT, age INTEGER);
|
||||
INSERT INTO users (name, age) VALUES ('Bob', 24);
|
||||
INSERT INTO users (name, age) VALUES ('Alice', 42);
|
||||
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user