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 plan apply

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

Overview

Concrete tool for planning and applying staged result edits through the RPC handler provided by the sqmeow-core engine.

Description

The Core::plan method handles the plan RPC method. It reads staged changes from the grid, looks up the result's connection, rejects read-only and aggregate results, and delegates to Backend::plan to generate dialect-specific DML statements for review. The statements are returned directly (not an event).

The Core::apply method handles the apply RPC method. It reads the approved statements from the user's review, looks up the connection, rejects read-only and aggregate results, registers the call as running, creates a Deadline, and delegates to Backend::apply to run the statements transactionally. Cancellation is cooperative: the call's token or the deadline can request cancellation, but adapters must report sent writes' actual outcomes. Cancelled means no changes were committed (for transactional dialects).

After successful apply, rows from INSERT RETURNING are stashed via Session::stash_inserted for the next query run to display.

Usage

  • Plan: User stages cell edits in the grid and requests a plan; DML statements are shown for review.
  • Apply: User approves statements; they are executed transactionally and the outcome is reported through apply:done.

Code Reference

Source Location

  • Repository: sqmeow.nvim
  • File: core/sqmeow-core/src/server/edits.rs
  • Lines: L16-42 (plan), L47-93 (apply)

Signature

impl Core {
    pub(super) fn plan(&self, args: &Args) -> Result<Value, String>;
    pub(super) fn apply(self: Arc<Self>, args: &Args) -> Started;
}

Import

// Internal to Core; dispatched from on_request handler.

I/O Contract

Inputs

Name Type Required Description
call_id CallId Yes /// Result to edit
changes Changes Yes /// (plan) Staged cell edits from grid
statements Option<Vec<String>> Yes /// (apply) Approved DML statements from review
conn_id ConnId Yes /// (apply) Connection id

Outputs

Name Type Description
plan Value::Array(Vec<String>) /// DML statements for review (direct reply)
apply reply Value::from(conn_id) /// Acknowledgement before async work
apply:done Event /// conn_id, statements count, error (if any)

Usage Examples

Planning edits

// RPC: plan { call_id: 1, changes: { updates: [{row: 0, cells: [{column: 1, value: "Alice"}]}] } }
// Returns: ["UPDATE \"users\" SET \"name\" = $1 WHERE \"id\" = $2"]

Applying approved edits

// RPC: apply { conn_id: 1, call_id: 1, statements: ["UPDATE \"users\" SET \"name\" = 'Alice' WHERE \"id\" = 1"] }
// Emits: apply:done { conn_id: 1, statements: 1 }
// On error: apply:done { conn_id: 1, statements: 1, error: "..." }

Related Pages

Implements Principle

Requires Environment

  • (Requires open writable database connection)

Page Connections

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