Principle:2giosangmitom Sqmeow nvim DML Generation
| 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:
- Delete:
DELETE FROM "table" WHERE "id" = $1— locate by key columns. - Insert:
INSERT INTO "table" ("col") VALUES ($1) RETURNING *— with dialect-specific row return. MySQL has no RETURNING; it reads back by key orLAST_INSERT_ID(). - 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