pub struct ConnPool { /* private fields */ }
Expand description
SQLite connection pool.
This is a specialized connection pool that is defined specifically for sqlite, and only allows a single writer but multiple readers.
Implementations§
Source§impl ConnPool
impl ConnPool
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Return the pool size.
In effect, this is the size of the read-only pool plus one (for the read/write connection).
Sourcepub fn reader(&self) -> Result<PooledConnection<SqliteConnectionManager>, Error>
pub fn reader(&self) -> Result<PooledConnection<SqliteConnectionManager>, Error>
Acquire a read-only connection.
§Errors
r2d2::Error
will be returned if a read-only connection could not be
acquired.
Sourcepub fn writer(&self) -> WrConn
pub fn writer(&self) -> WrConn
Acquire the read/write connection.
If the writer is already taken, then block and wait for it to become available.
Sourcepub fn try_writer(&self) -> Option<WrConn>
pub fn try_writer(&self) -> Option<WrConn>
Attempt to acquire the writer connection.
Returns Some(conn)
if the writer connection was available at the time
of the request. Returns None
if the writer has already been taken.
Source§impl ConnPool
Special queries.
impl ConnPool
Special queries.
Sourcepub fn freelist_count(&self) -> Result<usize, Error>
pub fn freelist_count(&self) -> Result<usize, Error>
Return the number of unused pages.
§Errors
Error::R2D2
indicates that it wasn’t possible to acquire a read-only
connection from the connection pool. Error::Sqlite
means it was not
possible to query the free page list count.
Source§impl ConnPool
Read-only connection processing.
impl ConnPool
Read-only connection processing.
Sourcepub fn run_ro<T, F, E>(&self, f: F) -> Result<T, E>
pub fn run_ro<T, F, E>(&self, f: F) -> Result<T, E>
Run a read-only database operation.
§Errors
The error type E
is used to return application-defined errors, though
it must be possible to convert a r2d2::Error
into E
using the From
trait.
Sourcepub fn run_ro_thrd<F>(&self, f: F) -> Result<(), Error>
Available on crate feature tpool
only.
pub fn run_ro_thrd<F>(&self, f: F) -> Result<(), Error>
tpool
only.Run a read-only database operation on a thread.
§Errors
r2d2::Error
is returned if it wasn’t possible to acquire a read-only
connection from the connection pool.
§Panics
A thread pool must be associated with the ConnPool
or this method
will panic.
Sourcepub fn run_ro_thrd_result<T, E, F>(
&self,
f: F,
) -> Result<WaitCtx<T, (), E>, Error>
Available on crate feature tpool
only.
pub fn run_ro_thrd_result<T, E, F>( &self, f: F, ) -> Result<WaitCtx<T, (), E>, Error>
tpool
only.Run a read-only database operation on a thread, allowing the caller to
receive the Result<T, E>
of the supplied closure using a
one-shot channel.
The supplied closure in f
should return a Result<T, E>
where the Ok
case will be passed as a “set” value through the swctx
channel, and the
Err
case will be passed as a “fail” value.
§Errors
r2d2::Error
is returned if it wasn’t possible to acquire a read-only
connection from the connection pool.
§Panics
A thread pool must be associated with the ConnPool
or this method
will panic.
Source§impl ConnPool
Read/Write connection processing.
impl ConnPool
Read/Write connection processing.
Sourcepub fn run_rw_thrd<F>(&self, f: F)
Available on crate feature tpool
only.
pub fn run_rw_thrd<F>(&self, f: F)
tpool
only.Run a read/write database operation on a thread.
The supplied closure should return an Option<usize>
, where the Some()
case denotes the specified amount of “dirt” should be added to the write
connection. None
means no dirt should be added.
§Panics
A thread pool must be associated with the ConnPool
or this method
will panic.
Sourcepub fn run_rw_thrd_result<T, E, F>(&self, f: F) -> WaitCtx<T, (), E>
Available on crate feature tpool
only.
pub fn run_rw_thrd_result<T, E, F>(&self, f: F) -> WaitCtx<T, (), E>
tpool
only.Run a read/write database operation on a thread, allowing the
caller to receive the Result<T, E>
of the supplied closure using a
one-shot channel.
The supplied closure in f
should return a Result<T, E>
where the Ok
case will be passed as a “set” value through the swctx
channel, and the
Err
case will be passed as a “fail” value.
§Panics
A thread pool must be associated with the ConnPool
or this method
will panic.