pub struct SqlxMySqlConnection { /* private fields */ }Trait Implementations§
Source§impl Connection for SqlxMySqlConnection
impl Connection for SqlxMySqlConnection
Source§fn session_reset_sql(&self) -> Option<&'static str>
fn session_reset_sql(&self) -> Option<&'static str>
MySQL 的 COM_RESET_CONNECTION 是协议命令而非 SQL 语句(sqlx 未暴露),
归还连接时用单条 SET SESSION 复位关键会话变量。必须保持单语句且
版本无关:transaction_isolation/max_execution_time 在 MySQL 5.7、
MariaDB 上名称为 tx_isolation/max_statement_time,故不在此复位;
隔离级别由事务层按“下一事务”作用域下发(R3),不会残留到会话。
Source§fn take_session_dirty(&mut self) -> bool
fn take_session_dirty(&mut self) -> bool
R5 脏标记(v10.13.1):读取并清除脏标记(take 语义)。 返回 false 时池跳过复位语句——连接从未执行过 SET/USE,会话仍是默认状态。
Source§fn mark_session_clean(&mut self)
fn mark_session_clean(&mut self)
复位语句执行成功后由池调用;复位 SQL 是 SET,执行路径会置脏,这里统一清零
Source§fn execute_with_params<'a>(
&'a mut self,
sql: &'a str,
params: &'a [Value],
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>>
fn execute_with_params<'a>( &'a mut self, sql: &'a str, params: &'a [Value], ) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>>
MySQL 参数绑定执行(INSERT/UPDATE/DELETE)
使用 sqlx prepared statement 绑定参数。MySQL 协议原生支持 ? 占位符。
对 Value::Bool/I8..=I64/U8..=U64/F32/F64/String/Bytes 直接 bind;
其他类型回退为 to_string() 后以 TEXT 绑定。
Source§fn query_with_params<'a>(
&'a mut self,
sql: &'a str,
params: &'a [Value],
) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>
fn query_with_params<'a>( &'a mut self, sql: &'a str, params: &'a [Value], ) -> Pin<Box<dyn Future<Output = Result<QueryRows, DbError>> + Send + 'a>>
MySQL 参数绑定查询(SELECT,HashMap 映射)
Source§fn query_values<'a>(
&'a mut self,
sql: &'a str,
) -> Pin<Box<dyn Future<Output = Result<QueryValues, DbError>> + Send + 'a>>
fn query_values<'a>( &'a mut self, sql: &'a str, ) -> Pin<Box<dyn Future<Output = Result<QueryValues, DbError>> + Send + 'a>>
MySQL 位置式查询(SELECT,无参数)
绕过 HashMap 行映射,返回 (列名, 按列序号的值矩阵)。适用于 SELECT ALL 大结果集。
Source§fn query_values_with_params<'a>(
&'a mut self,
sql: &'a str,
params: &'a [Value],
) -> Pin<Box<dyn Future<Output = Result<QueryValues, DbError>> + Send + 'a>>
fn query_values_with_params<'a>( &'a mut self, sql: &'a str, params: &'a [Value], ) -> Pin<Box<dyn Future<Output = Result<QueryValues, DbError>> + Send + 'a>>
MySQL 参数绑定位置式查询(SELECT)
Source§fn query_stream<'a>(
&'a mut self,
sql: &'a str,
) -> Pin<Box<dyn Stream<Item = Result<HashMap<String, Value>, DbError>> + Send + 'a>>
fn query_stream<'a>( &'a mut self, sql: &'a str, ) -> Pin<Box<dyn Stream<Item = Result<HashMap<String, Value>, DbError>> + Send + 'a>>
MySQL 流式查询:逐行返回结果,避免大结果集 fetch_all 内存峰值
使用 sqlx::query::fetch 获取行流,逐行映射为 HashMap<String, Value>。
流正常消费完毕后连接归还 self.conn;若提前 drop 流,连接通过
PoolConnection::drop 归还到 sqlx 池,但 self.conn 变为 None。
Source§fn execute<'a>(
&'a mut self,
sql: &'a str,
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>>
fn execute<'a>( &'a mut self, sql: &'a str, ) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'a>>
Source§fn query<'a>(
&'a mut self,
sql: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<HashMap<String, Value>>, DbError>> + Send + 'a>>
fn query<'a>( &'a mut self, sql: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<HashMap<String, Value>>, DbError>> + Send + 'a>>
Source§fn begin_transaction<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>
fn begin_transaction<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>
Source§fn commit<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>
fn commit<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>
Source§fn rollback<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>
fn rollback<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>
Source§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Source§fn in_transaction(&self) -> bool
fn in_transaction(&self) -> bool
Source§fn close<'a>(
&'a mut self,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>
fn close<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'a>>
Source§fn query_stream_cursor<'a>(
&'a mut self,
sql: &'a str,
_batch_size: usize,
) -> Pin<Box<dyn Stream<Item = Result<HashMap<String, Value>, DbError>> + Send + 'a>>
fn query_stream_cursor<'a>( &'a mut self, sql: &'a str, _batch_size: usize, ) -> Pin<Box<dyn Stream<Item = Result<HashMap<String, Value>, DbError>> + Send + 'a>>
batch_size 分批拉取,避免大结果集内存峰值。 Read moreSource§impl Drop for SqlxMySqlConnection
impl Drop for SqlxMySqlConnection
Auto Trait Implementations§
impl !RefUnwindSafe for SqlxMySqlConnection
impl !UnwindSafe for SqlxMySqlConnection
impl Forget for SqlxMySqlConnection
impl Freeze for SqlxMySqlConnection
impl Send for SqlxMySqlConnection
impl Sync for SqlxMySqlConnection
impl Unpin for SqlxMySqlConnection
impl UnsafeUnpin for SqlxMySqlConnection
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<C> ConnectionExt for Cwhere
C: Connection + ?Sized,
impl<C> ConnectionExt for Cwhere
C: Connection + ?Sized,
Source§fn prepare_cached<'a>(
&'a mut self,
cache: &'a PreparedStatementCache,
sql: &'a str,
params: &'a [Value],
) -> Pin<Box<dyn Future<Output = Result<Vec<HashMap<String, Value>>, 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<Vec<HashMap<String, Value>>, DbError>> + Send + 'a>>
Source§fn 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>
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