bindings/javascript: Improve error when prepare() called after close()

This commit is contained in:
Pekka Enberg
2025-08-06 07:48:15 +03:00
parent f6fb786cc9
commit 79412ea2cc
4 changed files with 19 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ pub struct Database {
io: Arc<dyn turso_core::IO>,
conn: Arc<turso_core::Connection>,
is_memory: bool,
is_open: RefCell<bool>,
}
#[napi]
@@ -76,6 +77,7 @@ impl Database {
io,
conn,
is_memory,
is_open: RefCell::new(true),
})
}
@@ -85,6 +87,12 @@ impl Database {
self.is_memory
}
/// Returns whether the database connection is open.
#[napi(getter)]
pub fn open(&self) -> bool {
*self.is_open.borrow()
}
/// Executes a batch of SQL statements.
///
/// # Arguments
@@ -167,6 +175,7 @@ impl Database {
/// `Ok(())` if the database is closed successfully.
#[napi]
pub fn close(&self) -> Result<()> {
*self.is_open.borrow_mut() = false;
// Database close is handled automatically when dropped
Ok(())
}