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

Implementation:2giosangmitom Sqmeow nvim Core export

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

Overview

Concrete tool for exporting retained query results to files or clipboard through the RPC handler provided by the sqmeow-core engine.

Description

The Core::export method handles the export RPC method. It accepts a call id, format, row/column scope, headers flag, and optional path. Without a path, the encoded text is returned in the export:done event for the clipboard. With a path, the text is written to the file asynchronously.

The Core::export_preview method handles the export_preview RPC method, rendering up to 100 rows as text for the export dialog preview. It returns the text directly (not an event).

The Core::format helper resolves the export format from RPC args, including dialect-specific SQL options. For SQL format, the dialect is resolved from the result's connection (or the dialect arg), the table name from table, and batch/create flags. Non-SQL dialects are rejected for SQL export.

Usage

  • Export: User selects a format and optional path; results are encoded and either written to file or returned as text.
  • Preview: The export dialog shows a preview of the first 100 rows in the selected format.

Code Reference

Source Location

  • Repository: sqmeow.nvim
  • File: core/sqmeow-core/src/server/exports.rs
  • Lines: L18-39 (export), L42-73 (export_preview), L76-120 (write_export), L123-151 (format), L153-160 (emit_export)

Signature

impl Core {
    pub(super) fn export(self: Arc<Self>, args: &Args) -> Started;
    pub(super) fn export_preview(&self, args: &Args) -> Result<Value, String>;
    async fn write_export(self: Arc<Self>, call_id: CallId, format: Format, (rows, every): (Rows, bool), columns: Option<Vec<usize>>, headers: bool, path: Option<String>);
    fn format(&self, args: &Args, call_id: CallId) -> Result<Format, String>;
    fn emit_export(&self, call_id: CallId, outcome: Result<Vec<(&str, Value)>, String>);
}

Import

// Internal to Core; dispatched from on_request handler.

I/O Contract

Inputs

Name Type Required Description
call_id CallId Yes /// Result to export
format Format Yes /// Export format (resolved from args + connection dialect)
offset/limit usize No /// Row range (default: all rows)
all bool No /// Export all rows ignoring active view (default: false)
columns Option<Vec<usize>> No /// Column selection (default: all)
headers bool No /// (CSV) Include header row (default: true)
path Option<String> No /// File path (None = clipboard text)

Outputs

Name Type Description
reply Value::from(call_id) /// Acknowledgement before async work
export:done Event /// call_id, text/path, rows, bytes, or error
export_preview Value /// Encoded preview text (direct reply)

Usage Examples

Exporting to a file

// RPC: export { call_id: 1, format: "csv", path: "/tmp/results.csv", all: true }
// Emits: export:done { call_id: 1, path: "/tmp/results.csv", rows: 42, bytes: 1024 }

Exporting to clipboard

// RPC: export { call_id: 1, format: "json" }
// Emits: export:done { call_id: 1, text: "[[1,\"Alice\"],...]", rows: 42, bytes: 256 }

Related Pages

Implements Principle

Requires Environment

  • (Requires filesystem for file export)

Page Connections

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