bind/js: Apply pluck's logic to all methods

This commit is contained in:
Diego Reis
2025-05-26 17:14:33 -03:00
parent b60fd81995
commit b012d07aa3
2 changed files with 29 additions and 2 deletions

View File

@@ -65,13 +65,13 @@ test("Empty prepared statement should throw", async (t) => {
);
});
test("Test pragma", async (t) => {
test("Test pragma()", async (t) => {
const [db] = await connect(":memory:");
t.true(typeof db.pragma("cache_size")[0].cache_size === "number");
t.true(typeof db.pragma("cache_size", { simple: true }) === "number");
});
test("Test bind()", async (t) => {
test("Statement binded with bind() shouldn't be binded again", async (t) => {
const [db] = await connect(":memory:");
db.prepare("CREATE TABLE users (name TEXT, age INTEGER)").run();
db.prepare("INSERT INTO users (name, age) VALUES (?, ?)").run("Alice", 42);
@@ -90,6 +90,19 @@ test("Test bind()", async (t) => {
);
});
test("Test pluck(): Rows should only have the values of the first column", async (t) => {
const [db] = await connect(":memory:");
db.prepare("CREATE TABLE users (name TEXT, age INTEGER)").run();
db.prepare("INSERT INTO users (name, age) VALUES (?, ?)").run("Alice", 42);
db.prepare("INSERT INTO users (name, age) VALUES (?, ?)").run("Bob", 24);
let stmt = db.prepare("SELECT * FROM users").pluck();
for (const row of stmt.iterate()) {
t.truthy(row.name);
t.true(typeof row.age === "undefined");
}
});
const connect = async (path) => {
const db = new Database(path);
return [db];