pub struct UnifiedPool { /* private fields */ }Expand description
统一连接池:包装 Pool + AnyBackend,5 后端透明切换(v2.2.0 新增)
供 sz-rust AppState 持有 Arc<UnifiedPool>,业务代码无需感知后端类型。
所有方法委托内部 Pool,零能力丢失。
Implementations§
Source§impl UnifiedPool
impl UnifiedPool
Sourcepub async fn connect(dsn: &str) -> Result<Self, DbError>
pub async fn connect(dsn: &str) -> Result<Self, DbError>
连接数据库,根据 DSN 自动识别后端,使用默认 PoolConfig
默认配置:max_size=10, timeout=30s
Sourcepub async fn connect_with_config(
dsn: &str,
config: PoolConfig,
) -> Result<Self, DbError>
pub async fn connect_with_config( dsn: &str, config: PoolConfig, ) -> Result<Self, DbError>
连接数据库,根据 DSN 自动识别后端,使用自定义 PoolConfig
Sourcepub fn from_pool(pool: Pool, backend: AnyBackend) -> Self
pub fn from_pool(pool: Pool, backend: AnyBackend) -> Self
从已有的 Pool 构造 UnifiedPool(零成本迁移)
供 sz-rust 从 Arc<Pool> 迁移到 Arc<UnifiedPool>:
ⓘ
let unified = UnifiedPool::from_pool(existing_pool, AnyBackend::MySql);Sourcepub fn backend(&self) -> AnyBackend
pub fn backend(&self) -> AnyBackend
获取后端类型
Sourcepub async fn acquire(&self) -> Result<PooledConnection, PoolError>
pub async fn acquire(&self) -> Result<PooledConnection, PoolError>
获取连接(委托 Pool::acquire)
Sourcepub async fn status(&self) -> PoolStatus
pub async fn status(&self) -> PoolStatus
获取连接池状态(委托 Pool::status)
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for UnifiedPool
impl !UnwindSafe for UnifiedPool
impl Freeze for UnifiedPool
impl Send for UnifiedPool
impl Sync for UnifiedPool
impl Unpin for UnifiedPool
impl UnsafeUnpin for UnifiedPool
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 more