#[non_exhaustive]pub enum StreamingQueryResult {
SelectStreaming {
columns: Vec<String>,
rows: Box<dyn Iterator<Item = Result<Vec<Value>>> + Send>,
order_by: Option<Vec<OrderByExpr>>,
limit: Option<usize>,
offset: Option<usize>,
distinct: bool,
max_result_rows: Option<usize>,
size_hint: Option<usize>,
},
SelectReady {
columns: Vec<String>,
rows: Vec<Vec<Value>>,
},
SelectColumnar {
columns: Vec<String>,
segments: Vec<ColumnarSeg>,
row_indices: Option<Vec<usize>>,
num_rows: usize,
row_map: RowMap,
order_by: Option<Vec<OrderByExpr>>,
},
Modification {
affected_rows: usize,
},
Definition {
message: String,
},
}Expand description
🚀 流式查询结果(方案 C:零内存开销)
返回迭代器而不是 Vec,实现真正的流式查询。
#[non_exhaustive]: new variants may be added in future minor versions.
Prefer materialize() / for_each() / row_count() over matching the
enum directly — those accessors are stable across versions.
§示例
// 新 API:流式迭代
let result = db.execute_streaming("SELECT * FROM robots WHERE age < 25")?;
result.for_each(|columns, row| {
println!("{:?}: {:?}", columns, row);
Ok(())
})?;Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
SelectStreaming
SELECT 流式结果
Fields
order_by: Option<Vec<OrderByExpr>>🔧 ORDER BY 子句(在 materialize() 时应用)
SelectReady
🚀 Pre-materialized SELECT result (zero-overhead for fast PK paths)
SelectColumnar
🚀 Columnar result — typed arrays, zero per-row Vec
Fields
segments: Vec<ColumnarSeg>Column segments (Fixed or Text), one per output column
order_by: Option<Vec<OrderByExpr>>ORDER BY clauses to apply during materialization (None = no sort). Carried here so the zero-copy columnar scan path can still honor ORDER BY (expression/alias/ordinal) at materialize time.
Modification
INSERT/UPDATE/DELETE result
Definition
CREATE/DROP result
Implementations§
Source§impl StreamingQueryResult
impl StreamingQueryResult
Sourcepub fn materialize(self) -> Result<QueryResult>
pub fn materialize(self) -> Result<QueryResult>
🔥 物化结果集(供向后兼容的 execute() 使用)
将流式结果立即加载到内存中,转换为 QueryResult。
Sourcepub fn materialize_with_hint(
self,
size_hint: Option<usize>,
) -> Result<QueryResult>
pub fn materialize_with_hint( self, size_hint: Option<usize>, ) -> Result<QueryResult>
Sourcepub fn affected_rows(&self) -> usize
pub fn affected_rows(&self) -> usize
便利方法:逐行处理(零内存开销) 获取影响行数
Sourcepub fn row_count(&self) -> usize
pub fn row_count(&self) -> usize
Get row count without full materialization. O(1) for columnar/ready results.
Sourcepub fn materialize_with_limit(
self,
max_rows: Option<usize>,
) -> Result<(QueryResult, bool)>
pub fn materialize_with_limit( self, max_rows: Option<usize>, ) -> Result<(QueryResult, bool)>
Materialize with an explicit row limit. Returns (QueryResult, has_more). has_more is true when the limit was hit (more rows exist in storage).
Sourcepub fn for_each<F>(
self,
callback: F,
max_rows: Option<usize>,
) -> Result<ForEachResult>
pub fn for_each<F>( self, callback: F, max_rows: Option<usize>, ) -> Result<ForEachResult>
Process rows one at a time with a callback. O(1) memory for simple queries.
- No ORDER BY/DISTINCT: true streaming, O(1) memory, callback per-row
- ORDER BY + LIMIT: Top-K heap, O(LIMIT) memory
- ORDER BY no LIMIT: full sort, O(N) memory
- DISTINCT: O(unique rows) memory
When max_rows is hit, iteration stops and has_more is set to true.
Auto Trait Implementations§
impl !RefUnwindSafe for StreamingQueryResult
impl !Sync for StreamingQueryResult
impl !UnwindSafe for StreamingQueryResult
impl Freeze for StreamingQueryResult
impl Send for StreamingQueryResult
impl Unpin for StreamingQueryResult
impl UnsafeUnpin for StreamingQueryResult
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<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