mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-19 06:55:18 +01:00
adjust javascript turso bindings for reuse in turso-sync-js package
This commit is contained in:
@@ -8,7 +8,7 @@ repository.workspace = true
|
||||
description = "The Turso database library Node bindings"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
|
||||
[dependencies]
|
||||
turso_core = { workspace = true }
|
||||
|
||||
@@ -54,9 +54,14 @@ class Database {
|
||||
opts.timeout = opts.timeout === undefined ? 0 : opts.timeout;
|
||||
|
||||
this.db = new NativeDB(path, opts);
|
||||
this.memory = this.db.memory;
|
||||
const db = this.db;
|
||||
|
||||
this.initialize(db, opts.path, opts.readonly);
|
||||
}
|
||||
static create() {
|
||||
return Object.create(this.prototype);
|
||||
}
|
||||
initialize(db, name, readonly) {
|
||||
this.db = db;
|
||||
this.memory = db.memory;
|
||||
Object.defineProperties(this, {
|
||||
inTransaction: {
|
||||
get() {
|
||||
@@ -65,12 +70,12 @@ class Database {
|
||||
},
|
||||
name: {
|
||||
get() {
|
||||
return path;
|
||||
return name;
|
||||
},
|
||||
},
|
||||
readonly: {
|
||||
get() {
|
||||
return opts.readonly;
|
||||
return readonly;
|
||||
},
|
||||
},
|
||||
open: {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user