pub struct Database { /* private fields */ }Expand description
Wrapper around a rusqlite::Connection with project-standard pragmas
applied and migrations run.
Implementations§
Source§impl Database
impl Database
Sourcepub fn open(path: &Path) -> Result<Database>
pub fn open(path: &Path) -> Result<Database>
Open or create a SQLite database at path, apply pragmas, and run
any pending migrations.
Tilde-expansion is applied to path.
§Errors
TgaError::DbErrorfor SQLite-level failures.TgaError::MigrationErrorif a migration fails.
Sourcepub fn open_in_memory() -> Result<Database>
pub fn open_in_memory() -> Result<Database>
Sourcepub fn connection(&self) -> &Connection
pub fn connection(&self) -> &Connection
Borrow the underlying connection (read-only).
Sourcepub fn connection_mut(&mut self) -> &mut Connection
pub fn connection_mut(&mut self) -> &mut Connection
Borrow the underlying connection mutably.
Sourcepub fn journal_mode(&self) -> Result<String>
pub fn journal_mode(&self) -> Result<String>
Return the active journal mode (e.g. "wal" or "memory").
§Errors
Returns TgaError::DbError if the pragma query fails.
Sourcepub fn schema_version(&self) -> Result<i64>
pub fn schema_version(&self) -> Result<i64>
Sourcepub fn wal_checkpoint(&self, mode: CheckpointMode) -> Result<()>
pub fn wal_checkpoint(&self, mode: CheckpointMode) -> Result<()>
Checkpoint the WAL into the main database file.
Why: SQLite WAL mode defers writes to a separate -wal file; if the
process exits (or is killed) before a checkpoint, the main database
file can lag behind the WAL. On clean exit callers should call
wal_checkpoint(CheckpointMode::Truncate) to flush and zero the WAL,
guaranteeing durability. During long-running writes, periodic
wal_checkpoint(CheckpointMode::Passive) calls limit the data-loss
window on crash. See bug #298.
What: executes PRAGMA wal_checkpoint(<mode>) and logs the result.
Returns Ok(()) on success; returns an error if the checkpoint pragma
fails (e.g. SQLITE_CORRUPT).
§Checkpoint modes
CheckpointMode::Passive— copies frames from the WAL without blocking writers. Safe to call mid-run; used for periodic crash- resilience checkpoints.CheckpointMode::Truncate— flushes all WAL frames to the main database and truncates the WAL file to zero. Call on clean exit to guarantee durability and cap the WAL file size.
§Errors
Returns TgaError::DbError if the pragma query fails.
§Test
See tests::wal_checkpoint_truncate_zeroes_wal_on_file_db.
Auto Trait Implementations§
impl !Freeze for Database
impl !RefUnwindSafe for Database
impl !Sync for Database
impl !UnwindSafe for Database
impl Send for Database
impl Unpin for Database
impl UnsafeUnpin for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more