mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
Merge 'bindings/javascript: Add database property to Statement' from Anton Harniakou
Implements `.database` property on Statement object. ```js let stmt = db.prepare("SELECT 1"); stmt.database == db // will return the database object the stmt was create with ``` Reviewed-by: Diego Reis (@el-yawd) Closes #1671
This commit is contained in:
commit
c7ec4a6270
3 changed files with 19 additions and 2 deletions
|
@ -95,6 +95,12 @@ test("Test exec()", async (t) => {
|
|||
}
|
||||
});
|
||||
|
||||
test("Test Statement.database gets the database object", async t => {
|
||||
const [db] = await connect(":memory:");
|
||||
let stmt = db.prepare("SELECT 1");
|
||||
t.is(stmt.database, db);
|
||||
});
|
||||
|
||||
|
||||
const connect = async (path) => {
|
||||
const db = new Database(path);
|
||||
|
|
|
@ -155,6 +155,12 @@ test("Test exec()", async (t) => {
|
|||
}
|
||||
});
|
||||
|
||||
test("Test Statement.database gets the database object", async t => {
|
||||
const [db] = await connect(":memory:");
|
||||
let stmt = db.prepare("SELECT 1");
|
||||
t.is(stmt.database, db);
|
||||
});
|
||||
|
||||
const connect = async (path) => {
|
||||
const db = new Database(path);
|
||||
return [db];
|
||||
|
|
|
@ -32,7 +32,7 @@ class Database {
|
|||
*/
|
||||
prepare(sql) {
|
||||
try {
|
||||
return new Statement(this.db.prepare(sql));
|
||||
return new Statement(this.db.prepare(sql), this);
|
||||
} catch (err) {
|
||||
throw convertError(err);
|
||||
}
|
||||
|
@ -148,8 +148,9 @@ class Database {
|
|||
* Statement represents a prepared SQL statement that can be executed.
|
||||
*/
|
||||
class Statement {
|
||||
constructor(stmt) {
|
||||
constructor(stmt, database) {
|
||||
this.stmt = stmt;
|
||||
this.db = database;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,6 +177,10 @@ class Statement {
|
|||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
get database() {
|
||||
return this.db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the SQL statement and returns an info object.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue