Skip to main content

Module unified_pool

Module unified_pool 

Source
Expand description

UnifiedPool — 统一连接池抽象(v2.2.0 A-3)

包装 sz_orm_core::Pool(完整连接池)+ AnyBackend,提供 5 后端透明的统一类型。 供 sz-rust AppState 持有单一类型 Arc<UnifiedPool>,业务代码无需感知后端类型。

§设计

  • UnifiedPoolPool 的 newtype 包装,所有方法委托 Pool(零能力丢失)
  • from_pool 提供零成本迁移路径:sz-rust 从 Arc<Pool> 迁移到 Arc<UnifiedPool>
  • connect/connect_with_config 根据 DSN 自动识别后端并创建完整连接池

§用法

use sz_orm_sqlx::UnifiedPool;

// 从 DSN 自动识别后端,创建完整连接池
let pool = UnifiedPool::connect("mysql://root:pass@127.0.0.1/db").await?;
let mut conn = pool.acquire().await?;

// 运行时切换后端
let pg_pool = UnifiedPool::connect("postgres://user:pass@127.0.0.1/db").await?;
let d = pg_pool.dialect(); // 自动返回 PostgreSqlDialect

Structs§

MultiPoolRegistry
v3.2.0:多池注册表 — 统一管理多个后端的 UnifiedPool
UnifiedPool
统一连接池:包装 Pool + AnyBackend,5 后端透明切换(v2.2.0 新增)