pub struct ConnectionPool<DB>where
DB: Database,{ /* private fields */ }Expand description
A database connection pool
Implementations§
Source§impl ConnectionPool<Postgres>
impl ConnectionPool<Postgres>
Sourcepub async fn new_postgres(
url: &str,
config: PoolConfig,
) -> Result<ConnectionPool<Postgres>, PoolError>
Available on native and crate feature database only.
pub async fn new_postgres( url: &str, config: PoolConfig, ) -> Result<ConnectionPool<Postgres>, PoolError>
native and crate feature database only.Create a new PostgreSQL connection pool
§Examples
use reinhardt_db::pool::{ConnectionPool, PoolConfig};
let config = PoolConfig::default();
// For doctest purposes, using SQLite in-memory instead of PostgreSQL
let pool = ConnectionPool::new_sqlite("sqlite::memory:", config).await.unwrap();
assert!(pool.url().contains("memory"));
assert_eq!(pool.config().max_connections, 10);Source§impl ConnectionPool<MySql>
impl ConnectionPool<MySql>
Sourcepub async fn new_mysql(
url: &str,
config: PoolConfig,
) -> Result<ConnectionPool<MySql>, PoolError>
Available on native and crate feature database only.
pub async fn new_mysql( url: &str, config: PoolConfig, ) -> Result<ConnectionPool<MySql>, PoolError>
native and crate feature database only.Create a new MySQL connection pool
§Examples
use reinhardt_db::pool::{ConnectionPool, PoolConfig};
let config = PoolConfig::default();
// For doctest purposes, using SQLite in-memory instead of MySQL
let pool = ConnectionPool::new_sqlite("sqlite::memory:", config).await.unwrap();
assert!(pool.url().contains("memory"));
assert_eq!(pool.config().max_connections, 10);Source§impl ConnectionPool<Sqlite>
impl ConnectionPool<Sqlite>
Sourcepub async fn new_sqlite(
url: &str,
config: PoolConfig,
) -> Result<ConnectionPool<Sqlite>, PoolError>
Available on native and crate feature database only.
pub async fn new_sqlite( url: &str, config: PoolConfig, ) -> Result<ConnectionPool<Sqlite>, PoolError>
native and crate feature database only.Create a new SQLite connection pool
§Examples
use reinhardt_db::pool::{ConnectionPool, PoolConfig};
let config = PoolConfig::default();
// Using in-memory SQLite for doctest
let pool = ConnectionPool::new_sqlite("sqlite::memory:", config).await.unwrap();
assert!(pool.url().contains("memory"));
assert!(pool.config().max_connections > 0);Source§impl<DB> ConnectionPool<DB>where
DB: Database,
impl<DB> ConnectionPool<DB>where
DB: Database,
Sourcepub async fn add_listener(&self, listener: Arc<dyn PoolEventListener>)
Available on native and crate feature database only.
pub async fn add_listener(&self, listener: Arc<dyn PoolEventListener>)
native and crate feature database only.Add an event listener
Sourcepub async fn acquire(&self) -> Result<PooledConnection<DB>, PoolError>
Available on native and crate feature database only.
pub async fn acquire(&self) -> Result<PooledConnection<DB>, PoolError>
native and crate feature database only.Acquire a connection from the pool with event emission
§Examples
use reinhardt_db::pool::{ConnectionPool, PoolConfig};
let config = PoolConfig::default();
let pool = ConnectionPool::new_postgres("postgresql://user:pass@localhost/test", config)
.await
.unwrap();
// Acquire a connection
let conn = pool.acquire().await;
assert!(conn.is_ok());Sourcepub fn inner(&self) -> &Pool<DB>
Available on native and crate feature database only.
pub fn inner(&self) -> &Pool<DB>
native and crate feature database only.Get the underlying pool
Sourcepub fn config(&self) -> &PoolConfig
Available on native and crate feature database only.
pub fn config(&self) -> &PoolConfig
native and crate feature database only.Get pool configuration
Sourcepub async fn close(&self)
Available on native and crate feature database only.
pub async fn close(&self)
native and crate feature database only.Close the pool
Attempts to gracefully close the pool with a 5-second timeout. If active connections are not returned within this time, the pool will be forcefully closed.
Sourcepub fn url(&self) -> String
Available on native and crate feature database only.
pub fn url(&self) -> String
native and crate feature database only.Get the database URL with password masked for safe display
Returns the database URL with any password replaced by ***
to prevent credential exposure in logs and debug output.
Use url_raw() when the actual password is needed for reconnection.
Source§impl ConnectionPool<Postgres>
impl ConnectionPool<Postgres>
Sourcepub async fn recreate(&mut self) -> Result<(), PoolError>
Available on native and crate feature database only.
pub async fn recreate(&mut self) -> Result<(), PoolError>
native and crate feature database only.Recreate the pool with the same configuration
§Examples
use reinhardt_db::pool::{ConnectionPool, PoolConfig};
let config = PoolConfig::default();
// For doctest purposes, using SQLite in-memory instead of PostgreSQL
let mut pool = ConnectionPool::new_sqlite("sqlite::memory:", config)
.await
.unwrap();
// Recreate the pool
pool.recreate().await.unwrap();
assert_eq!(pool.config().max_connections, 10);Source§impl ConnectionPool<MySql>
impl ConnectionPool<MySql>
Sourcepub async fn recreate(&mut self) -> Result<(), PoolError>
Available on native and crate feature database only.
pub async fn recreate(&mut self) -> Result<(), PoolError>
native and crate feature database only.Recreate the pool with the same configuration
§Examples
use reinhardt_db::pool::{ConnectionPool, PoolConfig};
let config = PoolConfig::default();
// For doctest purposes, using SQLite in-memory instead of MySQL
let mut pool = ConnectionPool::new_sqlite("sqlite::memory:", config)
.await
.unwrap();
// Recreate the pool
pool.recreate().await.unwrap();
assert_eq!(pool.config().max_connections, 10);Source§impl ConnectionPool<Sqlite>
impl ConnectionPool<Sqlite>
Sourcepub async fn recreate(&mut self) -> Result<(), PoolError>
Available on native and crate feature database only.
pub async fn recreate(&mut self) -> Result<(), PoolError>
native and crate feature database only.Recreate the pool with the same configuration
§Examples
use reinhardt_db::pool::{ConnectionPool, PoolConfig};
let config = PoolConfig::default();
let mut pool = ConnectionPool::new_sqlite("sqlite::memory:", config)
.await
.unwrap();
// Recreate the pool
pool.recreate().await.unwrap();
assert!(pool.url().contains("memory"));Auto Trait Implementations§
impl<DB> !RefUnwindSafe for ConnectionPool<DB>
impl<DB> !UnwindSafe for ConnectionPool<DB>
impl<DB> Freeze for ConnectionPool<DB>
impl<DB> Send for ConnectionPool<DB>
impl<DB> Sync for ConnectionPool<DB>
impl<DB> Unpin for ConnectionPool<DB>
impl<DB> UnsafeUnpin for ConnectionPool<DB>where
Pool<DB>: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 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>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = !
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.