pub trait ConnectionExt: Connection {
// Provided methods
fn conn_id(&self) -> ConnId { ... }
fn prepare_cached<'a>(
&'a mut self,
cache: &'a PreparedStatementCache,
sql: &'a str,
params: &'a [Value],
) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>> { ... }
fn query_stream_unified<'a>(
&'a mut self,
sql: &'a str,
batch_size: usize,
) -> Result<Box<dyn AsyncRowStream + 'a>, DbError> { ... }
fn execute_batch_parallel<'a>(
&'a mut self,
sqls: &'a [String],
concurrency: usize,
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>> { ... }
fn query_with_result_cache<'a>(
&'a mut self,
cache: &'a QueryResultCache,
sql: &'a str,
params: &'a [Value],
depends_on: HashSet<String>,
) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>> { ... }
}Expand description
Connection 扩展 trait
为 Connection 提供三个扩展方法,所有方法有默认实现(向后兼容)。
适配器层可覆盖以接入真实功能。
Provided Methods§
Sourcefn prepare_cached<'a>(
&'a mut self,
cache: &'a PreparedStatementCache,
sql: &'a str,
params: &'a [Value],
) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>
fn prepare_cached<'a>( &'a mut self, cache: &'a PreparedStatementCache, sql: &'a str, params: &'a [Value], ) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>
PreparedStatement 句柄复用查询
默认实现:委托 query_with_params(无缓存收益,向后兼容)。
适配器覆盖此方法以接入 PreparedStatementCache。
Sourcefn query_stream_unified<'a>(
&'a mut self,
sql: &'a str,
batch_size: usize,
) -> Result<Box<dyn AsyncRowStream + 'a>, DbError>
fn query_stream_unified<'a>( &'a mut self, sql: &'a str, batch_size: usize, ) -> Result<Box<dyn AsyncRowStream + 'a>, DbError>
统一流式结果集
默认实现:委托 query_stream_cursor 包装为 BoxedCursorRowStream(降级)。
适配器覆盖此方法以提供真游标实现。
Sourcefn execute_batch_parallel<'a>(
&'a mut self,
sqls: &'a [String],
concurrency: usize,
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>>
fn execute_batch_parallel<'a>( &'a mut self, sqls: &'a [String], concurrency: usize, ) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>>
批量 DML 并行化
默认实现:委托 execute_batch(串行,向后兼容)。
concurrency == 0 退化为串行。
适配器覆盖此方法以利用多连接实现真正并行。
Sourcefn query_with_result_cache<'a>(
&'a mut self,
cache: &'a QueryResultCache,
sql: &'a str,
params: &'a [Value],
depends_on: HashSet<String>,
) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>
fn query_with_result_cache<'a>( &'a mut self, cache: &'a QueryResultCache, sql: &'a str, params: &'a [Value], depends_on: HashSet<String>, ) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>
查询结果缓存查询
查询流程:QueryResultCache → DB → 写入缓存。
与 prepare_cached 协同:适配器可覆盖此方法,在未命中时委托 prepare_cached。
depends_on:该查询依赖的表名(用于主动失效)。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".