pub struct ConnectionPool { /* private fields */ }Expand description
Connection pool for managing database connections
This pool provides:
- Concurrency limits via semaphore (max_connections)
- Connection health validation
- Performance metrics
- Graceful shutdown
Implementations§
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub async fn new(db: Arc<Database>, config: PoolConfig) -> Result<Self>
pub async fn new(db: Arc<Database>, config: PoolConfig) -> Result<Self>
Create a new connection pool
§Arguments
db- Database instance to create connections fromconfig- Pool configuration
§Example
use std::sync::Arc;
use libsql::Builder;
use do_memory_storage_turso::pool::{ConnectionPool, PoolConfig};
let db = Builder::new_local("test.db").build().await?;
let config = PoolConfig::default();
let pool = ConnectionPool::new(Arc::new(db), config).await?;Sourcepub async fn get(&self) -> Result<PooledConnection>
pub async fn get(&self) -> Result<PooledConnection>
Get a connection from the pool
This will:
- Wait for a semaphore permit (respects max_connections limit)
- Create a new connection from the database
- Optionally validate the connection health
- Return a PooledConnection guard that releases the permit on drop
§Errors
Returns error if:
- Timeout waiting for available connection slot
- Failed to create connection
- Connection health check fails
Sourcepub async fn statistics(&self) -> PoolStatistics
pub async fn statistics(&self) -> PoolStatistics
Get current pool statistics
Sourcepub async fn utilization(&self) -> f32
pub async fn utilization(&self) -> f32
Get current pool utilization (0.0 to 1.0)
Sourcepub async fn available_connections(&self) -> usize
pub async fn available_connections(&self) -> usize
Get number of available connection slots
Sourcepub async fn has_capacity(&self) -> bool
pub async fn has_capacity(&self) -> bool
Check if pool has available capacity
Auto Trait Implementations§
impl Freeze for ConnectionPool
impl !RefUnwindSafe for ConnectionPool
impl Send for ConnectionPool
impl Sync for ConnectionPool
impl Unpin for ConnectionPool
impl UnsafeUnpin for ConnectionPool
impl !UnwindSafe for ConnectionPool
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.