Merge 'bindings/javascript: Add source property to Statement' from Anton Harniakou

Let's you get the source string that was used to create the prepared
statement.

Reviewed-by: Diego Reis (@el-yawd)

Closes #1670
This commit is contained in:
Jussi Saurio 2025-06-09 08:24:47 +03:00
commit 94e334a44a
3 changed files with 21 additions and 0 deletions

View file

@ -214,6 +214,12 @@ test("Test Statement.database gets the database object", async t => {
t.is(stmt.database, db); t.is(stmt.database, db);
}); });
test("Test Statement.source", async t => {
const [db] = await connect(":memory:");
let sql = "CREATE TABLE t (id int)";
let stmt = db.prepare(sql);
t.is(stmt.source, sql);
});
const connect = async (path) => { const connect = async (path) => {
const db = new Database(path); const db = new Database(path);

View file

@ -215,6 +215,13 @@ test("Test Statement.database gets the database object", async t => {
t.is(stmt.database, db); t.is(stmt.database, db);
}); });
test("Test Statement.source", async t => {
const [db] = await connect(":memory:");
let sql = "CREATE TABLE t (id int)";
let stmt = db.prepare(sql);
t.is(stmt.source, sql);
});
const connect = async (path) => { const connect = async (path) => {
const db = new Database(path); const db = new Database(path);
return [db]; return [db];

View file

@ -178,10 +178,18 @@ class Statement {
return this; return this;
} }
get source() {
return this.stmt.source;
}
get reader() { get reader() {
throw new Error("not implemented"); throw new Error("not implemented");
} }
get source() {
return this.stmt.source;
}
get database() { get database() {
return this.db; return this.db;
} }