pub struct ConnectionPool { /* private fields */ }Expand description
A pool of rusqlite::Connections.
Internally, the pool is represented with a fixed-capacity, thread-safe queue.
Implementations§
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn new<F>(capacity: usize, new_conn_fn: F) -> Result<Self, Error>
pub fn new<F>(capacity: usize, new_conn_fn: F) -> Result<Self, Error>
Create a new connection pool.
This opens capacity number of connections using new_conn_fn and adds
them to the inner queue.
If any of the connections fail to open, all previously successful connections (if any) are dropped and the error is returned.
Sourcepub fn pop(&self) -> Option<ConnectionHandle>
pub fn pop(&self) -> Option<ConnectionHandle>
Pop a connection from the queue if one is available.
If None is returned, all connections are currently in use.
The inner connection is returned to the pool upon dropping the handle.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
The total number of simultaneous connections managed by the pool, specified by the user upon construction.
Sourcepub fn all_connections_ready(&self) -> bool
pub fn all_connections_ready(&self) -> bool
Returns true if the inner idle queue is full, i.e. all Connections
are available for use.
Sourcepub fn close(&self) -> Vec<Result<(), (Connection, Error)>>
pub fn close(&self) -> Vec<Result<(), (Connection, Error)>>
Manually close the pool and all connections in the inner queue.
Returns the Connection::close result for each connection in the queue.
If it is necessary that results are returned for all connections, care
must be taken to ensure all ConnectionHandles are dropped and that
all_connections_ready returns true
before calling this method. Otherwise, connections not in the queue will
be closed upon the last ConnectionHandle dropping.
All connections closed during this call will be unavailable in future
calls to pop.
Trait Implementations§
Source§impl Clone for ConnectionPool
impl Clone for ConnectionPool
Source§fn clone(&self) -> ConnectionPool
fn clone(&self) -> ConnectionPool
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more