rdbc_rs/future/connpool.rs
1use std::sync::{Arc, Mutex};
2
3use anyhow::Result;
4
5use crate::{driver, BoxedDriver};
6
7/// Database connection pool trait.
8pub trait ConnectionPool: Sized {
9 /// Create new connection pool
10 /// # Arguments
11 /// * `driver` - SQL thread safe driver instance
12 /// * `url` - SQL driver connect url
13 fn new<S>(driver_name: S, driver: Arc<Mutex<BoxedDriver>>, url: S) -> Result<Self>
14 where
15 S: Into<String> + AsRef<str>;
16
17 /// Get new connection from pool or create new one from driver.
18 fn get_conn(&self) -> Result<Box<dyn driver::Connection>>;
19
20 /// Release one connection return to pool.
21 ///
22 /// # Arguments
23 ///
24 /// * `conn` - Unused connection instance
25 fn release_conn(&self, conn: Box<dyn driver::Connection>);
26}