Skip to main content

SqliteStoreConfig

Struct SqliteStoreConfig 

Source
pub struct SqliteStoreConfig {
    pub pool_size: u32,
    pub read_pool_size: u32,
    pub cache_size_kib: u32,
    pub mmap_size: Option<u64>,
    pub busy_timeout: Duration,
    pub synchronous: Synchronous,
    pub thread_pool: Option<Arc<ScheduledThreadPool>>,
    pub connection_init: Option<ConnectionInitHook>,
}
Expand description

Per-store connection tuning. Default is a low-memory profile sized for one SqliteStore per WhatsApp session on a single process: a single pooled connection (operations are serialized internally, so a second would only idle) sharing one process-wide r2d2 thread pool, with a 512 KiB page cache. Raise pool_size for real concurrent DB access — it drives both the pool and the internal serialization in lockstep — or cache_size_kib for a hotter/larger DB; pass a thread_pool to control r2d2’s management threads (e.g. share your own across crates).

Fields§

§pool_size: u32

Max concurrent operations: r2d2 max_size AND the internal semaphore permits, kept in lockstep. Clamped to at least 1.

Raising this makes writes concurrent, which SQLite does not want: two deferred transactions that both read and then write deadlock on the upgrade, and busy_timeout cannot break it. Leave it at 1 and reach for read_pool_size instead — that is the knob for concurrency, and it is safe because WAL readers never contend for the write lock.

§read_pool_size: u32

Extra connections reserved for read-only work, each free to run while a write holds the write permit. 0 (default) keeps every operation on the single queue, exactly as before this knob existed.

WAL supports many concurrent readers alongside one writer, but that was unreachable while one pool_size governed both the pool and the serialization semaphore: the setting that would admit readers also admitted concurrent writers. These connections are additional — the write path keeps its own, so a burst of readers can never starve the writer.

Costs one connection’s page cache (cache_size_kib) each, which is why it is off by default in a process holding many per-session stores.

§cache_size_kib: u32

PRAGMA cache_size, in KiB per connection.

§mmap_size: Option<u64>

PRAGMA mmap_size, in bytes. None (default) leaves mmap off — the current behavior. When set, pages are read through a reclaimable, file-backed memory map instead of the heap page cache, which helps a process holding many small per-session DBs (the mapped pages are OS-reclaimable, unlike heap cache bytes).

Caveat: mmap I/O covers reads of the main database file; in WAL mode (this store’s default) writes still go through the WAL, and a checkpoint briefly falls back to non-mmap I/O. 0 disables mmap the same as None.

§busy_timeout: Duration

PRAGMA busy_timeout.

§synchronous: Synchronous

PRAGMA synchronous.

§thread_pool: Option<Arc<ScheduledThreadPool>>

r2d2 connection-management thread pool. None shares one process-wide pool so many stores don’t each spawn their own threads.

§connection_init: Option<ConnectionInitHook>

Optional hook run first on every new pooled connection, before the store’s own pragmas, WAL setup, and migrations. See ConnectionInitHook for the contract; set via SqliteStoreConfig::with_connection_init.

Implementations§

Source§

impl SqliteStoreConfig

Source

pub fn with_read_pool_size(self, n: u32) -> Self

Reserve n connections for read-only work, so reads stop queueing behind the write permit. See read_pool_size for what it costs and why raising pool_size is not the same thing.

Source

pub fn with_mmap_size(self, bytes: u64) -> Self

Set PRAGMA mmap_size (bytes), enabling file-backed memory-mapped reads. Builder-style so new optional knobs don’t force struct-literal churn; pass 0 to keep mmap off. See the SqliteStoreConfig::mmap_size caveat.

Source

pub fn with_connection_init<F>(self, hook: F) -> Self
where F: Fn(&mut SqliteConnection) -> Result<(), Box<dyn Error + Send + Sync>> + Send + Sync + 'static,

Install a per-connection init hook, run before the store’s pragmas, WAL setup, and migrations on every pooled connection (see ConnectionInitHook).

The canonical use is SQLCipher keying, where the key must be applied — and ideally verified — before anything else touches the database:

use diesel::prelude::*;

let config = SqliteStoreConfig::default().with_connection_init(move |conn| {
    diesel::sql_query("PRAGMA key = 'my-passphrase';").execute(conn)?;
    // Verify the key: this fails on a wrongly-keyed database.
    diesel::sql_query("SELECT count(*) FROM sqlite_master;").execute(conn)?;
    Ok(())
});

Linking a SQLCipher-enabled SQLite is the caller’s responsibility: disable this crate’s default bundled-sqlite feature and depend on libsqlite3-sys with a SQLCipher build (e.g. its bundled-sqlcipher feature) instead.

Trait Implementations§

Source§

impl Clone for SqliteStoreConfig

Source§

fn clone(&self) -> SqliteStoreConfig

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
Source§

impl Default for SqliteStoreConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Spawnable for T
where T: Send + 'static,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more