diff --git a/bindings/wasm/lib.rs b/bindings/wasm/lib.rs index b32367abd..47302d6bc 100644 --- a/bindings/wasm/lib.rs +++ b/bindings/wasm/lib.rs @@ -1,4 +1,4 @@ -use limbo_core::{OpenFlags, Page, Result, IO}; +use limbo_core::{OpenFlags, Page, Pager, Result, WalFile, IO}; use std::cell::RefCell; use std::rc::Rc; use std::sync::Arc; @@ -20,7 +20,13 @@ impl Database { .open_file(path, limbo_core::OpenFlags::None, false) .unwrap(); let page_io = Rc::new(DatabaseStorage::new(file)); - let wal = Rc::new(RefCell::new(Wal {})); + let db_header = Pager::begin_open(page_io.clone()).unwrap(); + let wal_path = format!("{}-wal", path); + let wal = Rc::new(RefCell::new(WalFile::new( + io.clone(), + wal_path, + db_header.borrow().page_size as usize, + ))); let db = limbo_core::Database::open(io, page_io, wal).unwrap(); let conn = db.connect(); Database { db, conn } @@ -56,7 +62,7 @@ impl Statement { } array.push(&row_array); } - Ok(limbo_core::RowResult::IO) => todo!(), + Ok(limbo_core::RowResult::IO) => {} Ok(limbo_core::RowResult::Done) => break, Err(e) => panic!("Error: {:?}", e), } @@ -109,15 +115,15 @@ impl limbo_core::File for File { _buffer: Rc>, _c: Rc, ) -> Result<()> { - todo!() + Ok(()) } fn sync(&self, _c: Rc) -> Result<()> { - todo!() + Ok(()) } fn size(&self) -> Result { - todo!() + Ok(self.vfs.size(self.fd)) } } @@ -213,65 +219,6 @@ impl limbo_core::DatabaseStorage for DatabaseStorage { } } -pub struct Wal {} - -impl limbo_core::Wal for Wal { - fn begin_read_tx(&self) -> Result<()> { - Ok(()) - } - - fn end_read_tx(&self) -> Result<()> { - Ok(()) - } - - fn find_frame(&self, _page_id: u64) -> Result> { - Ok(None) - } - - fn begin_write_tx(&self) -> Result<()> { - todo!() - } - - fn end_write_tx(&self) -> Result<()> { - todo!() - } - - fn read_frame( - &self, - _frame_id: u64, - _page: Rc>, - _buffer_pool: Rc, - ) -> Result<()> { - todo!() - } - - fn should_checkpoint(&self) -> bool { - false - } - - fn append_frame( - &mut self, - _page: Rc>, - _db_size: u32, - _pager: &limbo_core::Pager, - _write_counter: Rc>, - ) -> Result<()> { - todo!() - } - - fn checkpoint( - &mut self, - _pager: &limbo_core::Pager, - _write_counter: Rc>, - ) -> Result { - todo!() - } - - fn sync(&mut self) -> Result { - Ok(limbo_core::CheckpointStatus::Done) - } -} - #[wasm_bindgen(module = "/vfs.js")] extern "C" { type VFS; @@ -290,6 +237,9 @@ extern "C" { #[wasm_bindgen(method)] fn pread(this: &VFS, fd: i32, buffer: &mut [u8], offset: usize) -> i32; + + #[wasm_bindgen(method)] + fn size(this: &VFS, fd: i32) -> u64; } #[wasm_bindgen(start)] diff --git a/bindings/wasm/vfs.js b/bindings/wasm/vfs.js index 64e0326b1..19527d288 100644 --- a/bindings/wasm/vfs.js +++ b/bindings/wasm/vfs.js @@ -19,6 +19,11 @@ class VFS { pwrite(fd, buffer, offset) { return fs.writeSync(fd, buffer, 0, buffer.length, offset); } + + size(fd) { + let stats = fs.fstatSync(fd); + return BigInt(stats.size); + } } -module.exports = { VFS }; \ No newline at end of file +module.exports = { VFS }; diff --git a/core/lib.rs b/core/lib.rs index fab59ed31..7fdc257a4 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -25,8 +25,7 @@ use std::{cell::RefCell, rc::Rc}; #[cfg(feature = "fs")] use storage::database::FileStorage; use storage::sqlite3_ondisk::DatabaseHeader; -#[cfg(feature = "fs")] -use storage::wal::WalFile; +pub use storage::wal::WalFile; use translate::optimizer::optimize_plan; use translate::planner::prepare_select_plan; diff --git a/core/storage/wal.rs b/core/storage/wal.rs index 1e4e6f313..713e2c838 100644 --- a/core/storage/wal.rs +++ b/core/storage/wal.rs @@ -57,7 +57,6 @@ pub trait Wal { fn sync(&mut self) -> Result; } -#[cfg(feature = "fs")] pub struct WalFile { io: Arc, wal_path: String, @@ -80,7 +79,6 @@ pub enum CheckpointStatus { IO, } -#[cfg(feature = "fs")] impl Wal for WalFile { /// Begin a read transaction. fn begin_read_tx(&self) -> Result<()> { @@ -232,7 +230,6 @@ impl Wal for WalFile { } } -#[cfg(feature = "fs")] impl WalFile { pub fn new(io: Arc, wal_path: String, page_size: usize) -> Self { Self {