Skip to main content

DbOptions

Struct DbOptions 

Source
pub struct DbOptions {
Show 16 fields pub path: PathBuf, pub busy_timeout: Duration, pub key: Option<Zeroizing<String>>, pub raw_key: Option<Zeroizing<[u8; 32]>>, pub profile: CacheProfile, pub durability: DurabilityProfile, pub foreign_keys: bool, pub integrity_check_on_open: bool, pub integrity: IntegrityCheck, pub journal: JournalSelect, pub owner_only: bool, pub init: Option<ConnInit>, pub journal_env: Option<String>, pub per_host_fallback: bool, pub secure_delete: Option<bool>, pub optimize_on_open: bool,
}

Fields§

§path: PathBuf§busy_timeout: Duration

SQLite busy wait, installed before key verification or any bootstrap statement. Default: five seconds.

§key: Option<Zeroizing<String>>

SQLCipher passphrase-style key (base64-ish charset). See also DbOptions::raw_key.

§raw_key: Option<Zeroizing<[u8; 32]>>

SQLCipher raw 256-bit key, applied as x'<hex>' (no KDF). Takes precedence over key.

§profile: CacheProfile§durability: DurabilityProfile§foreign_keys: bool§integrity_check_on_open: bool

Legacy switch: true runs a full check on every open. Ignored when integrity is not Off.

§integrity: IntegrityCheck

Open-time integrity check (default Off). A failed check is DbError::Integrity, which open_writer_recovering treats as unreadable.

§journal: JournalSelect§owner_only: bool

Narrow the database and its sidecars to owner-only (0600) on unix. Default on. Set it to false when sibling processes must read the file (for example a helper running as another user); that is the intended switch, not a bug.

§init: Option<ConnInit>§journal_env: Option<String>

The app’s own kill-switch variable (e.g. CODERIGHT_SQLITE_JOURNAL_MODE), checked before JOURNAL_ENV.

§per_host_fallback: bool

When a rollback journal is in force (network mount, kill switch, or WAL refused), open the per-host sibling per_host_path instead of the requested file, so hosts sharing a network directory never share one rollback-journaled database. The requested file is not created. Default off.

§secure_delete: Option<bool>

Sets PRAGMA secure_delete on every connection at open: Some(true) overwrites freed pages, Some(false) does not, None (default) leaves SQLite’s compile-time default.

§optimize_on_open: bool

Run PRAGMA optimize on each writer connection at open (default true). Set it to false to leave planner statistics alone at open, for example when the file is opened only to inspect it. Readers never run it, whatever this is set to.

Implementations§

Source§

impl DbOptions

Source

pub fn restore_from(&self, backup_path: impl AsRef<Path>) -> Result<()>

Validate the backup first, then open the existing live database without bootstrap and restore it. Neither missing backup nor missing live DB is created. The backup must use the same SQLCipher key as these options.

Source§

impl DbOptions

Source

pub fn open_writer_migrated( &self, migrations: &[Migration], options: &MigrateOptions, ) -> Result<(Connection, MigrationReport)>

Open the writer and bring the schema up to date (see migrate); the pre-migration backup is keyed like the database itself.

Source

pub fn open_writer_migrated_or_degrade( &self, migrations: &[Migration], options: &MigrateOptions, policy: RecoveryPolicy, ) -> Result<OpenOrDegrade>

Open-or-degrade: Self::open_writer_migrated, with recovery for a stored database that is corrupt, not a database, or fails its integrity check, at open or during migration.

For such a failure, policy decides as in Self::open_writer_recovering: when it allows (quarantine_corrupt for a plain database, quarantine_keyed for a keyed one), the file and its sidecars move aside under the policy’s stamp and sidecar options (never deleted by default), and the database is created and migrated again. When it does not allow, the file is left untouched. Either way, if the store still cannot be opened, the connection is a private in-memory store that is migrated the same way only when policy.allow_in_memory_fallback explicitly acknowledges it (default refuse: the original error is returned). When acknowledged, OpenOrDegrade::degraded says so with in_memory: true, and the configured key remains applied.

Any other failure (busy, permission, I/O, a newer database, an invalid migration list) is returned as an error, because it does not show the stored data is damaged.

Source§

impl DbOptions

Source

pub fn open_writer_with_key_candidates( &self, candidates: &[Zeroizing<String>], ) -> Result<(Connection, usize)>

Try each passphrase in order; the first that decrypts opens the writer.

Source

pub fn open_writer_recovering( &self, policy: RecoveryPolicy, ) -> Result<OpenOutcome>

Open the writer; if the file is unreadable and the policy allows it, quarantine it and open a fresh database at the same path.

Source§

impl DbOptions

Source

pub fn open_writer_recovering_unreadable( &self, policy: RecoveryPolicy, unreadable: UnreadablePolicy, ) -> Result<UnreadableRecovery>

DbOptions::open_writer_recovering plus a policy for a database that cannot be read.

§Errors

DbError::Unreadable as above; the original error otherwise; a quarantine or reopen failure after the file was set aside (the old file stays preserved).

Source

pub fn open_writer_recovering_via( &self, policy: RecoveryPolicy, unreadable: UnreadablePolicy, open: impl FnMut() -> Result<Connection>, ) -> Result<UnreadableRecovery>

As DbOptions::open_writer_recovering_unreadable, with the open step supplied by the caller: it is called once for the first attempt and once more after a quarantine. This is the seam for tests that inject open errors and for apps with their own bootstrap.

Source§

impl DbOptions

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Source

pub fn with_journal_env(self, name: impl Into<String>) -> Self

Source

pub fn with_per_host_fallback(self, on: bool) -> Self

Source

pub fn without_optimize_on_open(self) -> Self

Turn PRAGMA optimize off at writer open (see DbOptions::optimize_on_open).

Source

pub fn effective_path(&self) -> PathBuf

The file connections actually open: the requested path, or its per-host sibling when Self::per_host_fallback applies (a rollback journal is in force, or a writer already fell back there).

Source

pub fn with_passphrase(self, key: impl Into<String>) -> Self

Source

pub fn with_raw_key(self, key: [u8; 32]) -> Self

Source

pub fn is_keyed(&self) -> bool

Source

pub fn open_writer(&self) -> Result<Connection>

Source

pub fn open_reader(&self) -> Result<Connection>

Source

pub fn open_read_only(&self) -> Result<Connection>

Open exactly path read-only, without creating it or running mutating bootstrap. URI parameters are passed to SQLite unchanged. Journal fallback, permissions, init, optimization, and migrations are skipped; key and timeout still apply.

Source

pub fn open_existing_writer(&self) -> Result<Connection>

Open exactly path read-write without CREATE or mutating bootstrap. Uses the same minimal setup as Self::open_read_only.

Source

pub fn open_in_memory(&self) -> Result<Connection>

Open a private, ephemeral database. path, filesystem permissions, journal selection/fallback, and mmap are ignored; other bootstrap options still apply.

Source

pub fn open_read_pool(&self, cap: usize) -> Result<ReadPool>

A read pool with ReadPoolOptions::new: read-write file handles, with query_only set and verified on every reader. Same as open_read_pool_with(cap, ReadPoolOptions::new()).

Source

pub fn open_read_pool_with( &self, cap: usize, pool: ReadPoolOptions, ) -> Result<ReadPool>

A read pool configured by ReadPoolOptions. A read-only pool needs the database to exist.

Trait Implementations§

Source§

impl Clone for DbOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.