Skip to main content

StreamApiExt

Trait StreamApiExt 

Source
pub trait StreamApiExt<M: Model> {
    // Required methods
    fn stream_buffered<'a, 'b: 'a, C: Connection + Send + 'b>(
        self,
        conn: &'b mut C,
    ) -> Pin<Box<dyn Stream<Item = Result<RowResult, DbError>> + Send + 'a>>;
    fn stream_with_backpressure<'a, 'b: 'a, C: Connection + Send + 'b>(
        self,
        conn: &'b mut C,
        buffer_size: usize,
    ) -> Result<Pin<Box<dyn Stream<Item = Result<RowResult, DbError>> + Send + 'a>>, DbError>;
}
Expand description

Stream API 扩展 trait

QueryBuilder<M> 提供 stream_buffered 兼容版方法和 stream_with_backpressure 背压方法。

Required Methods§

Source

fn stream_buffered<'a, 'b: 'a, C: Connection + Send + 'b>( self, conn: &'b mut C, ) -> Pin<Box<dyn Stream<Item = Result<RowResult, DbError>> + Send + 'a>>

兼容版流式查询(全量收集后逐行 yield)

保留 v2.0.0 stream 的行为,作为逃生舱。 推荐使用 stream(真游标,低内存)。

Source

fn stream_with_backpressure<'a, 'b: 'a, C: Connection + Send + 'b>( self, conn: &'b mut C, buffer_size: usize, ) -> Result<Pin<Box<dyn Stream<Item = Result<RowResult, DbError>> + Send + 'a>>, DbError>

背压流式查询(v2.2.0 B-4)

创建有界缓冲通道,缓冲区满时生产者阻塞(背压)。

§参数
  • conn:数据库连接
  • buffer_size:缓冲区容量(必须 > 0)
§错误
  • buffer_size == 0 → 返回 Err(DbError::InvalidInput)
let stream = query.stream_with_backpressure(&mut conn, 1000)?;
// 缓冲区容量 1000,满时生产者阻塞

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§