Skip to main content

UnifiedPool

Struct UnifiedPool 

Source
pub struct UnifiedPool { /* private fields */ }
Expand description

统一连接池:包装 Pool + AnyBackend,5 后端透明切换(v2.2.0 新增)

供 sz-rust AppState 持有 Arc<UnifiedPool>,业务代码无需感知后端类型。 所有方法委托内部 Pool,零能力丢失。

Implementations§

Source§

impl UnifiedPool

Source

pub async fn connect(dsn: &str) -> Result<Self, DbError>

连接数据库,根据 DSN 自动识别后端,使用默认 PoolConfig

默认配置:max_size=10, timeout=30s

Source

pub async fn connect_with_config( dsn: &str, config: PoolConfig, ) -> Result<Self, DbError>

连接数据库,根据 DSN 自动识别后端,使用自定义 PoolConfig

Source

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);
Source

pub fn backend(&self) -> AnyBackend

获取后端类型

Source

pub fn dialect(&self) -> Box<dyn Dialect>

返回对应后端的 Dialect 实例

Source

pub async fn acquire(&self) -> Result<PooledConnection, PoolError>

获取连接(委托 Pool::acquire)

Source

pub fn resize(&self, new_max: usize)

调整连接池大小(委托 Pool::resize)

Source

pub async fn close_all(&self)

关闭所有连接(委托 Pool::close_all)

Source

pub async fn status(&self) -> PoolStatus

获取连接池状态(委托 Pool::status)

Source

pub async fn prewarm(&self)

预热连接池(委托 Pool::prewarm)

Trait Implementations§

Source§

impl Debug for UnifiedPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more