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 DML Generation

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

Overview

A DML generation principle that translates staged cell edits into dialect-specific SQL statements (DELETE, INSERT, UPDATE) with correct quoting, clause syntax, and row-return mechanisms per database dialect.

Description

DML Generation is the principle of producing SQL data manipulation statements from staged result edits, with each dialect's specific syntax handled: identifier quoting ("name" for standard SQL, `name` for MySQL, [name] for MSSQL), row-return clauses (RETURNING * for PostgreSQL/SQLite/DuckDB, OUTPUT INSERTED.* for MSSQL, separate SELECT read-back for MySQL), and conditional insert syntax (IF NOT EXISTS for CQL).

This principle addresses the challenge of generating correct DML for 11 database dialects from a uniform Changes structure. The planner validates that rows exist, columns are editable, and the result has source provenance. Statements are generated in a fixed order (deletes → inserts → updates) to avoid conflicts. Value literals are quoted per dialect; SQL expressions (like now()) are inserted as-is.

Usage

Use this principle when generating DML from structured edits for multiple SQL dialects: handle quoting, RETURNING/OUTPUT/read-back, and conditional syntax per dialect.

Theoretical Basis

The principle translates staged edits to DML in fixed order:

  1. Delete: DELETE FROM "table" WHERE "id" = $1 — locate by key columns.
  2. Insert: INSERT INTO "table" ("col") VALUES ($1) RETURNING * — with dialect-specific row return. MySQL has no RETURNING; it reads back by key or LAST_INSERT_ID().
  3. Update: UPDATE "table" SET "col" = $1 WHERE "id" = $2 — set changed columns, locate by key.
# Abstract pattern (NOT real implementation):
def sql_plan(dialect, result, changes) -> list[str]:
    statements = []
    for row in changes.deletes:
        statements.append(delete_stmt(dialect, table, key_values(row)))
    for cells in changes.inserts:
        statements.append(insert_stmt(dialect, table, cells))  # + RETURNING/OUTPUT/read-back
    for row, cells in changes.live_updates():
        statements.append(update_stmt(dialect, table, cells, key_values(row)))
    return statements

Related Pages

Implemented By

Page Connections

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