Struct ConnPool

Source
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

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn run_ro<T, F, E>(&self, f: F) -> Result<T, E>
where T: Send + 'static, F: FnOnce(&Connection) -> Result<T, E> + Send + 'static, E: From<Error>,

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.

Source

pub fn run_ro_thrd<F>(&self, f: F) -> Result<(), Error>
where F: FnOnce(&Connection) + Send + 'static,

Available on crate feature 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.

Source

pub fn run_ro_thrd_result<T, E, F>( &self, f: F, ) -> Result<WaitCtx<T, (), E>, Error>
where T: Send + 'static, E: Debug + Send + 'static, F: FnOnce(&Connection) -> Result<T, E> + Send + 'static,

Available on crate feature 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.

Source

pub fn run_rw<T, E, F>(&self, f: F) -> Result<T, E>
where T: Send + 'static, E: Debug + Send + 'static, F: FnOnce(&mut WrConn) -> Result<T, E> + Send + 'static,

Run a read/write database operation.

§Errors

Returns an application-specific type E on error.

Source

pub fn run_rw_thrd<F>(&self, f: F)
where F: FnOnce(&mut WrConn) -> Option<usize> + Send + 'static,

Available on crate feature 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.

Source

pub fn run_rw_thrd_result<T, E, F>(&self, f: F) -> WaitCtx<T, (), E>
where T: Send + 'static, E: Debug + Send + 'static, F: FnOnce(&mut WrConn) -> Result<T, E> + Send + 'static,

Available on crate feature 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.

Source§

impl ConnPool

Source

pub fn incremental_vacuum(&self, n: Option<usize>) -> WaitCtx<(), (), Error>

Available on crate feature tpool only.

Trait Implementations§

Source§

impl Clone for ConnPool

Source§

fn clone(&self) -> ConnPool

Returns a duplicate of the value. Read more
1.0.0 · 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 = 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V