Skip to main content

SqliteReadPool

Struct SqliteReadPool 

Source
pub struct SqliteReadPool { /* private fields */ }
Expand description

SQLite Read Connection Pool

Manages a pool of read-only SQLite connections for concurrent reads. Each connection is opened with SQLITE_OPEN_READ_ONLY flag.

§Example

let pool = SqliteReadPool::new(&db_path, ReadPoolConfig::enabled(4))?;

// Acquire a pooled connection
let conn = pool.acquire().await?;
let count: i64 = conn.query_row("SELECT COUNT(*) FROM users", [], |row| row.get(0))?;
// Connection is returned to pool when `conn` is dropped

Implementations§

Source§

impl SqliteReadPool

Source

pub fn new(db_path: &Path, config: ReadPoolConfig) -> Result<Self>

Create a new read pool with the given configuration

Opens pool_size read-only connections to the database.

Source

pub async fn acquire(&self) -> Result<PooledSqliteConnection<'_>>

Acquire a pooled read-only connection

Waits up to the configured timeout for a connection to become available. Returns an error if the timeout is exceeded.

Source

pub fn try_acquire(&self) -> Result<Option<PooledSqliteConnection<'_>>>

Try to acquire a pooled read-only connection without waiting

Returns None if no connection is immediately available.

Source

pub fn available_permits(&self) -> usize

Get the number of available connections in the pool

Source

pub fn is_enabled(&self) -> bool

Check if pooling is enabled

Source

pub fn db_path(&self) -> &Path

Get the database path

Source

pub fn pool_size(&self) -> usize

Get the pool size

Source

pub fn acquire_blocking(&self) -> Result<PooledSqliteConnection<'_>>

Acquire a pooled read-only connection (blocking)

Blocks up to acquire_timeout waiting for an available connection.

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