pub trait PgExtensions: Send + Sync {
// Required methods
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 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 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;
}Expand description
PostgreSQL 扩展功能 trait
提供 PostgreSQL 特有的 LISTEN/NOTIFY 通道通信与 COPY FROM STDIN 批量导入功能。
这些功能在其他数据库(MySQL/SQLite)中没有对应实现,因此单独定义为扩展 trait,
仅由 SqlxPgConnection 实现。
§LISTEN/NOTIFY
PostgreSQL 的轻量级进程间通信机制:
LISTEN channel:订阅通道NOTIFY channel, payload:向通道发送通知
接收通知需配合 PgListener 或轮询 pg_notification 系列函数。
§COPY FROM STDIN
PostgreSQL 的高性能批量导入协议,比逐行 INSERT 快 10~100 倍。 数据通过专用协议流式传输,绕过 SQL 解析器。
Required Methods§
Sourcefn 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,
Sourcefn 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,
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".