mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-25 20:14:21 +01:00
bindings/javascript: Switch from RefCell to Cell
This commit is contained in:
@@ -13,7 +13,11 @@
|
||||
use napi::bindgen_prelude::*;
|
||||
use napi::{Env, Task};
|
||||
use napi_derive::napi;
|
||||
use std::{cell::RefCell, num::NonZeroUsize, sync::Arc};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
num::NonZeroUsize,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
/// Step result constants
|
||||
const STEP_ROW: u32 = 1;
|
||||
@@ -35,7 +39,7 @@ pub struct Database {
|
||||
io: Arc<dyn turso_core::IO>,
|
||||
conn: Arc<turso_core::Connection>,
|
||||
is_memory: bool,
|
||||
is_open: RefCell<bool>,
|
||||
is_open: Cell<bool>,
|
||||
}
|
||||
|
||||
#[napi]
|
||||
@@ -77,7 +81,7 @@ impl Database {
|
||||
io,
|
||||
conn,
|
||||
is_memory,
|
||||
is_open: RefCell::new(true),
|
||||
is_open: Cell::new(true),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -90,7 +94,7 @@ impl Database {
|
||||
/// Returns whether the database connection is open.
|
||||
#[napi(getter)]
|
||||
pub fn open(&self) -> bool {
|
||||
*self.is_open.borrow()
|
||||
self.is_open.get()
|
||||
}
|
||||
|
||||
/// Executes a batch of SQL statements.
|
||||
@@ -173,7 +177,7 @@ impl Database {
|
||||
/// `Ok(())` if the database is closed successfully.
|
||||
#[napi]
|
||||
pub fn close(&self) -> Result<()> {
|
||||
*self.is_open.borrow_mut() = false;
|
||||
self.is_open.set(false);
|
||||
// Database close is handled automatically when dropped
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user