adjust javascript turso bindings for reuse in turso-sync-js package

This commit is contained in:
Nikita Sivukhin
2025-08-07 01:31:48 +04:00
parent a1df9365a2
commit 1a2a1a9ca4
3 changed files with 26 additions and 10 deletions

View File

@@ -34,8 +34,9 @@ enum PresentationMode {
/// A database connection.
#[napi]
#[derive(Clone)]
pub struct Database {
_db: Arc<turso_core::Database>,
_db: Option<Arc<turso_core::Database>>,
io: Arc<dyn turso_core::IO>,
conn: Arc<turso_core::Connection>,
is_memory: bool,
@@ -76,13 +77,22 @@ impl Database {
.connect()
.map_err(|e| Error::new(Status::GenericFailure, format!("Failed to connect: {e}")))?;
Ok(Database {
Ok(Self::create(Some(db), io, conn, is_memory))
}
pub fn create(
db: Option<Arc<turso_core::Database>>,
io: Arc<dyn turso_core::IO>,
conn: Arc<turso_core::Connection>,
is_memory: bool,
) -> Self {
Database {
_db: db,
io,
conn,
is_memory,
is_open: Cell::new(true),
})
}
}
/// Returns whether the database is in memory-only mode.
@@ -418,7 +428,8 @@ impl Statement {
/// Async task for running the I/O loop.
pub struct IoLoopTask {
io: Arc<dyn turso_core::IO>,
// this field is set in the turso-sync-engine package
pub io: Arc<dyn turso_core::IO>,
}
impl Task for IoLoopTask {