mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-18 14:35:14 +01:00
bind/js: Apply pluck's logic to all methods
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user