pub struct DatabasePool { /* private fields */ }Expand description
Database connection pool
Implementations§
Source§impl DatabasePool
impl DatabasePool
Sourcepub async fn new(config: DatabaseConfig) -> Result<Self>
pub async fn new(config: DatabaseConfig) -> Result<Self>
Create a new database pool
Sourcepub fn from_pool(pool: SqlitePool) -> Self
pub fn from_pool(pool: SqlitePool) -> Self
Create a DatabasePool from an existing SqlitePool
Sourcepub async fn warmup(&self, target_connections: Option<u32>) -> Result<u32>
pub async fn warmup(&self, target_connections: Option<u32>) -> Result<u32>
Warm up the connection pool
Pre-populates the pool with connections to avoid cold start latency. This is useful during application startup to ensure connections are ready before handling requests.
§Arguments
target_connections- Number of connections to pre-create (defaults to min_connections)
§Example
let pool = DatabasePool::new(config).await?;
pool.warmup(Some(5)).await?; // Pre-create 5 connectionsSourcepub fn pool(&self) -> &SqlitePool
pub fn pool(&self) -> &SqlitePool
Get a reference to the underlying pool
Sourcepub async fn health_check(&self) -> Result<()>
pub async fn health_check(&self) -> Result<()>
Check if database is healthy
Sourcepub async fn begin(&self) -> Result<Transaction<'static, Sqlite>>
pub async fn begin(&self) -> Result<Transaction<'static, Sqlite>>
Begin a new transaction
Sourcepub async fn transaction<F, T, Fut>(&self, f: F) -> Result<T>where
F: FnOnce(Transaction<'static, Sqlite>) -> Fut,
Fut: Future<Output = Result<(Transaction<'static, Sqlite>, T)>>,
pub async fn transaction<F, T, Fut>(&self, f: F) -> Result<T>where
F: FnOnce(Transaction<'static, Sqlite>) -> Fut,
Fut: Future<Output = Result<(Transaction<'static, Sqlite>, T)>>,
Execute a closure within a transaction The transaction is committed if the closure returns Ok, rolled back otherwise
Sourcepub fn metrics(&self) -> PoolMetrics
pub fn metrics(&self) -> PoolMetrics
Get comprehensive pool metrics including health status
Sourcepub fn health_status(&self) -> PoolHealth
pub fn health_status(&self) -> PoolHealth
Get pool health status based on utilization and state
Sourcepub async fn acquire(&self) -> Result<PoolConnection<Sqlite>>
pub async fn acquire(&self) -> Result<PoolConnection<Sqlite>>
Acquire a connection from the pool
Sourcepub fn export_metrics(&self) -> HashMap<String, f64>
pub fn export_metrics(&self) -> HashMap<String, f64>
Export metrics in a format suitable for monitoring systems
Returns a map of metric names to values for integration with monitoring systems like Prometheus, DataDog, etc.
Trait Implementations§
Source§impl Clone for DatabasePool
impl Clone for DatabasePool
Source§fn clone(&self) -> DatabasePool
fn clone(&self) -> DatabasePool
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DatabasePool
impl !RefUnwindSafe for DatabasePool
impl Send for DatabasePool
impl Sync for DatabasePool
impl Unpin for DatabasePool
impl !UnwindSafe for DatabasePool
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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