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 Export

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

Overview

A result export principle that encodes retained query results as CSV, JSON, or SQL text, respecting active view scope, column selection, and dialect-specific quoting.

Description

Result Export is the principle of encoding rows from a retained ResultSet into a portable text format (CSV, JSON, or SQL INSERT statements) for saving to a file or copying to the clipboard. The export respects the active view (only exported rows in the view are included, unless all is set), column selection, and row range (offset/limit).

This principle addresses the challenge of exporting query results in multiple formats while preserving exact values and handling dialect-specific syntax. CSV uses polars_io::CsvWriter for native columns with Object fallback formatting. JSON encodes each row as an array of values. SQL generates INSERT statements with dialect-specific identifier quoting, optional CREATE TABLE preamble, and multi-row batch inserts (up to 500 rows per INSERT). Non-SQL dialects (Redis, MongoDB, SurrealDB) are rejected for SQL export.

The export dialect for SQL format is resolved from the result's connection (if open), or the dialect argument, defaulting to PostgreSQL.

Usage

Use this principle when a database tool exports query results: support multiple formats, respect active view and column scope, handle dialect-specific quoting, and offer both file and clipboard destinations.

Theoretical Basis

The principle encodes retained rows through format-specific encoders:

  1. Row resolution: Rows::resolve maps a row range through the active view (or all rows if all or no view).
  2. Column selection: chosen filters column indices to those that exist.
  3. CSV: Build a Polars frame with text/numeric projections; write with CsvWriter. Optional header row with original names.
  4. JSON: Encode each row as a JSON array of cell values (null, bool, number, string).
  5. SQL: For each row, generate INSERT INTO "table" ("col1", "col2") VALUES (val1, val2) with dialect quoting. Optional CREATE TABLE and batch mode (multi-row INSERT).
# Abstract pattern (NOT real implementation):
def write(result, format, rows, columns, headers) -> str:
    cols = columns or range(len(result.columns))
    match format:
        case CSV: return csv_encode(result, rows, cols, headers)
        case JSON: return json_encode(result, rows, cols)
        case SQL: return sql_insert_encode(result, rows, cols, format.dialect)

Related Pages

Implemented By

Page Connections

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