Skip to main content

StreamQueryTrait

Trait StreamQueryTrait 

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

M4 新增:流式查询 trait

将查询结果作为 Stream 返回,适合大数据量场景(避免一次性加载到内存)。

§示例

use sz_orm_core::paginator::{StreamQueryTrait, RowResult};
use futures::StreamExt;

let mut stream = query.stream(&mut conn);
while let Some(row) = stream.next().await {
    let row: RowResult = row?;
    // 处理...
}

Required Methods§

Source

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

返回流式查询结果

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§