Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:2giosangmitom Sqmeow nvim Result Retention

From Leeroopedia
Knowledge Sources
Domains Data_Model, Query_Execution
Last Updated 2026-10-16 14:00 GMT

Overview

A lossless data retention principle that stores query results in a Polars DataFrame with Object fallback, preserving exact values for editing, paging, and export while sharing buffers across readers.

Description

Result Retention is the principle of storing query results in a data model that preserves every value exactly as the database returned it, without type narrowing or precision loss. Native types (Boolean, Int64, Float64, String, Binary) use Arrow-backed Polars columns for efficient vectorized operations. Types that don't fit native columns (Decimal, Timestamp, Array, Unsupported) use an Object fallback column storing Cell values directly.

This principle addresses the challenge of supporting diverse database types (exact numerics, timestamps with timezones, arrays, JSON, binary, custom types) in a uniform in-memory model. Typed projections for views and exports read from the same shared frame without mutating source cells. Cloning a ResultSet shares Polars buffers through copy-on-write, so snapshot copies are cheap.

Key invariants:

  • Every data column has row_count cells; short rows are padded with NULL, excess cells are trimmed.
  • Internal column names are positional (__sqmeow_cell_N), so duplicate database labels never violate Polars' unique-name invariant.
  • Ingestion buffers (pending) are moved (not copied) into the frame on first read via frame().
  • A multi-statement run produces multiple calls but consumes one history slot; all calls in a run are evicted together.

Usage

Use this principle when a database tool needs to retain query results for paging, filtering, editing, and export after the query has finished. The lossless model ensures that editing writes back the exact values the database returned, and export produces the exact text.

Theoretical Basis

The principle combines native Polars columns with Object fallback:

  1. Ingestion: Adapters push row-shaped Cell values into per-column pending buffers.
  2. Finalization: frame() moves pending cells into native Polars columns where possible, or Object columns for types that don't fit. This is a one-time, lazy operation.
  3. Sharing: Cloning a ResultSet clones the DataFrame, which shares Arrow buffers through copy-on-write.
  4. Projections: View/export projections read from the shared frame, never writing back. Text projections format only requested rows in their original order.
# Abstract pattern (NOT real implementation):
class ResultSet:
    columns: list[Column]           # metadata: name, type, key, class
    pending: list[list[Cell]]       # ingestion buffers
    frame: OnceLock[DataFrame]      # finalized on first read

    def push_row(self, row: list[Cell]):
        row.resize(len(self.columns), Cell.Null)  # pad/trim
        for col, cell in zip(self.pending, row):
            col.append(cell)

    def frame(self) -> DataFrame:
        # Move pending into native columns (Int64, String, ...)
        # or Object columns (Decimal, Timestamp, Array, ...)
        return self.frame.get_or_init(lambda: finalize(self.pending))

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment