pub struct DbPools { /* private fields */ }Expand description
Read pool + dedicated single-connection write pool for the same SQLite
file. SQLite is single-writer system-wide, so a multi-connection pool
fighting for the writer lock just generates SQLITE_BUSY and (under
deferred transactions) SQLITE_BUSY_SNAPSHOT. Funnelling all writes
from one process through a single connection turns within-process
contention into an in-process queue (deterministic) instead of
SQLite-level lock contention (probabilistic, retry-required). Reads
keep the wider pool — WAL mode lets readers run concurrently.
Implementations§
Source§impl DbPools
impl DbPools
Sourcepub async fn open(
db_path: &Path,
max_read_connections: u32,
connect_timeout: Duration,
busy_timeout: Duration,
) -> Result<Self, Error>
pub async fn open( db_path: &Path, max_read_connections: u32, connect_timeout: Duration, busy_timeout: Duration, ) -> Result<Self, Error>
Open both pools for the SQLite file at db_path with shared PRAGMAs.
The write pool connects first so WAL mode (persisted in the database
header) is set before the read pool opens. max_read_connections
sizes only the read pool; the write pool is always single-connection
by design.
Sourcepub fn read(&self) -> &DbReadConnection
pub fn read(&self) -> &DbReadConnection
Borrow the read pool (multi-connection).
Sourcepub fn write(&self) -> &DbWriteConnection
pub fn write(&self) -> &DbWriteConnection
Borrow the write pool (single-connection, retries handled inside).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DbPools
impl !UnwindSafe for DbPools
impl Freeze for DbPools
impl Send for DbPools
impl Sync for DbPools
impl Unpin for DbPools
impl UnsafeUnpin for DbPools
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