pub struct SqlxPgConnection { /* private fields */ }Trait Implementations§
Source§impl Connection for SqlxPgConnection
impl Connection for SqlxPgConnection
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>>
PostgreSQL 参数绑定执行(INSERT/UPDATE/DELETE)
使用 sqlx prepared statement 绑定参数。PostgreSQL 协议使用 $1, $2, ... 占位符。
§类型映射说明
PostgreSQL 不支持无符号整数类型(u8/u16/u32/u64),因此无符号 Value 绑定 时按“最小可容纳的有符号类型“转换:
U8→i16(PostgreSQLSMALLINT)U16→i32(PostgreSQLINTEGER)U32→i64(PostgreSQLBIGINT)U64→i64(可能截断,仅适用于 <i64::MAX的值)
其他类型直接 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>>
PostgreSQL 参数绑定查询(SELECT,HashMap 映射)
类型映射规则与 Self::execute_with_params 相同。
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>>
PostgreSQL 位置式查询(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>>
PostgreSQL 参数绑定位置式查询(SELECT)
类型映射规则与 Self::execute_with_params 相同。
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>>
PostgreSQL 流式查询:逐行返回结果,避免大结果集 fetch_all 内存峰值
使用 sqlx::query::fetch 获取行流,逐行映射为 HashMap<String, Value>。
流正常消费完毕后连接归还 self.conn;若提前 drop 流,连接通过
PoolConnection::drop 归还到 sqlx 池,但 self.conn 变为 None。
注意:PostgreSQL 的 fetch 返回 Pin<Box<dyn Stream<...>>>(boxed trait object),
其析构函数可能持有 pool_conn 的借用,导致无法直接 self.conn = Some(pool_conn)。
通过显式 drop(row_stream) 提前结束借用,再归还连接。
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 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 SqlxPgConnection
impl Drop for SqlxPgConnection
Source§impl PgExtensions for SqlxPgConnection
impl PgExtensions for SqlxPgConnection
Source§fn listen<'life0, 'life1, 'async_trait>(
&'life0 mut self,
channel: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn listen<'life0, 'life1, 'async_trait>(
&'life0 mut self,
channel: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn notify<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
channel: &'life1 str,
payload: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn notify<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
channel: &'life1 str,
payload: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn copy_from_stdin<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn copy_from_stdin<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
sql: &'life1 str,
data: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for SqlxPgConnection
impl !UnwindSafe for SqlxPgConnection
impl Freeze for SqlxPgConnection
impl Send for SqlxPgConnection
impl Sync for SqlxPgConnection
impl Unpin for SqlxPgConnection
impl UnsafeUnpin for SqlxPgConnection
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
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