Implementation:2giosangmitom Sqmeow nvim ResultSet
| Knowledge Sources | |
|---|---|
| Domains | Data_Model, Query_Execution, View_Processing, Result_Export |
| Last Updated | 2026-10-16 14:00 GMT |
Overview
Concrete tool for losslessly retaining query results in a Polars DataFrame with Object fallback provided by the sqmeow-db crate.
Description
The ResultSet struct holds the rows one statement produced in a lossless Polars DataFrame. Adapters append row-shaped Cell values into ingestion buffers (pending), which are transferred to native Polars columns on first read via frame(). A typed view/export projection never replaces original cells — it reads from the same shared frame.
Key properties:
- Lossless retention: Native types (Bool, Int64, Float64, String, Binary) use Arrow columns; types that don't fit native columns (Decimal, Timestamp, Array, Unsupported) use an Object fallback column that stores
Cellvalues directly. Cloning aResultSetshares Polars buffers through copy-on-write. - Column metadata: Each
Columncarries name, database type name,TypeClass(for grid icons),KeyKind(for edit provenance), and a generated flag. - Source tracking: An optional
Sourcelinks editable cells back to source tables, collections, or Redis keys. - Truncation:
truncatedmarks results cut short by the row cap; paging/export cannot recover omitted rows. - Affected rows:
affectedaccumulates row-change counts for non-row-returning statements.
Usage
- Query execution: Adapters build a
ResultSetfrom query output;frame()finalizes ingestion before publication. - Local result processing: View/export projections read from
frame()without mutating source cells. - In-grid editing:
source()provides table/column provenance for DML generation. - Result export:
text_columnandcell_displayformat cells for CSV/JSON/SQL encoding.
Code Reference
Source Location
- Repository: sqmeow.nvim
- File: core/sqmeow-db/src/result.rs
- Lines: L72-431
Signature
pub struct ResultSet {
columns: Vec<Column>,
pending: Mutex<Vec<Vec<RetainedCell>>>,
frame: OnceLock<DataFrame>,
row_count: usize,
truncated: bool,
affected: Option<u64>,
elapsed: Duration,
statement: String,
source: Option<Source>,
}
impl ResultSet {
pub fn new(statement: impl Into<String>, columns: Vec<Column>) -> Self;
pub fn push_row(&mut self, row: Vec<Cell>);
pub fn frame(&self) -> &DataFrame;
pub fn cell(&self, row: usize, column: usize) -> Option<Cow<'_, Cell>>;
pub fn scalar(&self, row: usize, column: usize) -> Option<AnyValue<'_>>;
pub fn cell_display(&self, row: usize, column: usize, null: &str) -> Option<Cow<'_, str>>;
pub fn row_count(&self) -> usize;
pub fn columns(&self) -> &[Column];
pub fn source(&self) -> Option<&Source>;
pub fn set_source(&mut self, source: Option<Source>);
pub fn is_truncated(&self) -> bool;
pub fn mark_truncated(&mut self);
pub fn affected(&self) -> Option<u64>;
pub fn set_affected(&mut self, affected: u64);
pub fn elapsed(&self) -> Duration;
pub fn set_elapsed(&mut self, elapsed: Duration);
pub fn statement(&self) -> &str;
}
Import
use sqmeow_db::result::ResultSet;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| statement | impl Into<String> | Yes /// SQL that produced this result | |
| columns | Vec<Column> | Yes /// Column metadata (name, type_name) | |
| row | Vec<Cell> | Yes /// Row values (padded with NULL, excess trimmed) |
Outputs
| Name | Type | Description |
|---|---|---|
| frame | &DataFrame /// Shared lossless Polars frame (native + Object fallback) | |
| cell | Option<Cow<Cell>> /// One lossless cell by row/column index | |
| scalar | Option<AnyValue> /// Polars scalar (native types only) | |
| row_count | usize /// Number of rows held |
Usage Examples
Building a result from adapter output
let mut result = ResultSet::new("SELECT id, name FROM users", vec![
Column::new("id", "INTEGER"),
Column::new("name", "TEXT"),
]);
result.push_row(vec![Cell::Int(1), Cell::Text("Alice".into())]);
result.push_row(vec![Cell::Int(2), Cell::Text("Bob".into())]);
result.set_elapsed(Duration::from_millis(42));
// frame() finalizes ingestion into Polars columns
let frame: &DataFrame = result.frame();
Reading cells losslessly
// Native scalars read from Arrow; Object fallback reads from Cell
let cell = result.cell(0, 0); // Some(Cow::Borrowed(&Cell::Int(1)))
let scalar = result.scalar(0, 0); // Some(AnyValue::Int64(1))
let display = result.cell_display(0, 1, "NULL"); // Some(Cow::Borrowed("Alice"))
Related Pages
Implements Principle
Requires Environment
- (None — in-memory data model)