mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 00:45:37 +01:00
Merge 'bindings/javascript: Implement Database.open' from Lucas Forato
Reviewed-by: Diego Reis (@el-yawd) Closes #1834
This commit is contained in:
@@ -32,6 +32,11 @@ test("Property .readonly of database if not set", async (t) => {
|
||||
t.is(db.readonly, false);
|
||||
});
|
||||
|
||||
test("Property .open of database", async (t) => {
|
||||
const db = new Database("foobar.db");
|
||||
t.is(db.open, true);
|
||||
});
|
||||
|
||||
test("Statement.get() returns data", async (t) => {
|
||||
const [db] = await connect(":memory:");
|
||||
const stmt = db.prepare("SELECT 1");
|
||||
|
||||
@@ -35,8 +35,8 @@ pub struct Database {
|
||||
pub readonly: bool,
|
||||
// #[napi(writable = false)]
|
||||
// pub in_transaction: bool,
|
||||
// #[napi(writable = false)]
|
||||
// pub open: bool,
|
||||
#[napi(writable = false)]
|
||||
pub open: bool,
|
||||
#[napi(writable = false)]
|
||||
pub name: String,
|
||||
_db: Arc<turso_core::Database>,
|
||||
@@ -80,6 +80,7 @@ impl Database {
|
||||
memory,
|
||||
_db: db,
|
||||
conn,
|
||||
open: true,
|
||||
name: path,
|
||||
io,
|
||||
})
|
||||
@@ -135,6 +136,11 @@ impl Database {
|
||||
self.readonly
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn open(&self) -> bool {
|
||||
self.open
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn backup(&self) {
|
||||
todo!()
|
||||
@@ -208,8 +214,11 @@ impl Database {
|
||||
}
|
||||
|
||||
#[napi]
|
||||
pub fn close(&self) -> napi::Result<()> {
|
||||
self.conn.close().map_err(into_napi_error)?;
|
||||
pub fn close(&mut self) -> napi::Result<()> {
|
||||
if self.open {
|
||||
self.conn.close().map_err(into_napi_error)?;
|
||||
self.open = false;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user