pub struct ConnectionManager { /* private fields */ }Expand description
Multi-backend connection pool with optional automatic database creation.
The backend (Postgres, MySQL, or SQLite) is selected from the URL scheme.
If auto_create_db is enabled (default) and the target database doesn’t
exist, it is created before the pool is opened.
Implementations§
Source§impl ConnectionManager
impl ConnectionManager
Sourcepub async fn connect(config: DbkitConfig) -> Result<Self, DbkitError>
pub async fn connect(config: DbkitConfig) -> Result<Self, DbkitError>
Connect using a DbkitConfig.
Sourcepub async fn new(url: &str) -> Result<Self, DbkitError>
pub async fn new(url: &str) -> Result<Self, DbkitError>
Connect using a connection URL with default settings.
Shorthand for ConnectionManager::connect(DbkitConfig::from_url(url)).
Sourcepub async fn get_connection(&self) -> Result<PoolConnection<Any>, DbkitError>
pub async fn get_connection(&self) -> Result<PoolConnection<Any>, DbkitError>
Acquire a connection from the pool.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if the database is reachable.
Sourcepub fn connection_string(&self) -> &str
pub fn connection_string(&self) -> &str
The full connection string.
Sourcepub fn config(&self) -> &DbkitConfig
pub fn config(&self) -> &DbkitConfig
The config used to create this connection.
Sourcepub async fn pg_native_pool(&self) -> Result<PgPool, DbkitError>
pub async fn pg_native_pool(&self) -> Result<PgPool, DbkitError>
Create a native sqlx PgPool from this connection’s URL.
The multi-backend Any pool can only represent basic scalar types
(bool/int/float/text/bytes). This native pool restores full Postgres type
support — uuid, chrono timestamps, json/jsonb, arrays, etc. — for
the queries that need it. Use it alongside pool: Any for
portable work, the native pool for rich-typed Postgres work.
Errors if this connection is not Postgres.
let pg = conn.pg_native_pool().await?;
let row = sqlx::query("SELECT id, created_at FROM users WHERE id = $1")
.bind(some_uuid)
.fetch_one(&pg)
.await?;
let id: sqlx::types::Uuid = row.get("id");Sourcepub fn pool_status(&self) -> PoolStatus
pub fn pool_status(&self) -> PoolStatus
Pool health metrics.
Auto Trait Implementations§
impl !RefUnwindSafe for ConnectionManager
impl !UnwindSafe for ConnectionManager
impl Freeze for ConnectionManager
impl Send for ConnectionManager
impl Sync for ConnectionManager
impl Unpin for ConnectionManager
impl UnsafeUnpin for ConnectionManager
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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