Skip to content

Commit

Permalink
expose sqlite3_wal to rust as Sqlite3Wal and Sqlite3CreateWal
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed Nov 9, 2023
1 parent 8d1e459 commit 6da931b
Show file tree
Hide file tree
Showing 3 changed files with 403 additions and 36 deletions.
6 changes: 3 additions & 3 deletions libsql-sys-tmp/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
pub mod types;

pub use rusqlite::ffi::{
libsql_wal_methods, sqlite3, sqlite3_file, sqlite3_hard_heap_limit64,
sqlite3_io_methods, sqlite3_soft_heap_limit64, sqlite3_vfs, WalIndexHdr, SQLITE_CANTOPEN,
SQLITE_CHECKPOINT_FULL, SQLITE_CHECKPOINT_TRUNCATE, SQLITE_IOERR_WRITE, SQLITE_OK,
libsql_wal_methods, sqlite3, sqlite3_file, sqlite3_hard_heap_limit64, sqlite3_io_methods,
sqlite3_soft_heap_limit64, sqlite3_vfs, WalIndexHdr, SQLITE_CANTOPEN, SQLITE_CHECKPOINT_FULL,
SQLITE_CHECKPOINT_TRUNCATE, SQLITE_IOERR_WRITE, SQLITE_OK,
};

pub use rusqlite::ffi::libsql_pghdr as PgHdr;
Expand Down
18 changes: 12 additions & 6 deletions libsql-sys-tmp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use rusqlite::ffi::sqlite3;

use crate::wal::make_create_wal;

use self::wal::{Wal, CreateWal};

use self::wal::{CreateWal, Wal};

#[derive(Debug)]
pub struct Connection<W> {
Expand Down Expand Up @@ -54,18 +53,25 @@ impl<W: CreateWal> Connection<W> {
);

let conn_str = format!("file:{}?_journal_mode=WAL", path.display());
let conn = rusqlite::Connection::open_with_flags_and_wal(conn_str, flags, make_create_wal(create_wal))?;
let conn = rusqlite::Connection::open_with_flags_and_wal(
conn_str,
flags,
make_create_wal(create_wal),
)?;
unsafe {
let rc = rusqlite::ffi::sqlite3_wal_autocheckpoint(conn.handle(), auto_checkpoint as _);
if rc != 0 {
return Err(rusqlite::Error::SqliteFailure(
rusqlite::ffi::Error::new(rc),
Some("failed to set auto_checkpoint".into()),
rusqlite::ffi::Error::new(rc),
Some("failed to set auto_checkpoint".into()),
));
}
}

Ok(Connection { conn, _pth: PhantomData })
Ok(Connection {
conn,
_pth: PhantomData,
})
}

/// Returns the raw sqlite handle
Expand Down
Loading

0 comments on commit 6da931b

Please sign in to comment.