Principle:2giosangmitom Sqmeow nvim In Grid Editing
| Knowledge Sources | |
|---|---|
| Domains | Editing, Database |
| Last Updated | 2026-10-16 14:00 GMT |
Overview
A direct editing principle that allows users to edit database data through the results grid by staging cell changes, generating dialect-specific DML, reviewing statements, and applying them transactionally.
Description
In-Grid Editing is the principle of letting users modify database data directly in the query results grid, with a safety pipeline: stage → plan → review → apply. The editor stages cell changes (updates, deletes, inserts) as Changes. The engine generates dialect-specific DML statements from those changes using the result's source provenance. The user reviews the generated SQL before it is applied. Approved statements are executed transactionally.
This principle addresses the challenge of editing database data through a read-only query result: the result's columns must be traced back to source tables (TableBinder), primary/unique keys must be identified to locate rows, and DML must be generated with dialect-specific syntax (RETURNING, OUTPUT, read-back SELECT for MySQL). Only results with Source::Tables provenance are editable; aggregate results and results without source metadata are read-only.
Safety invariants:
- Read-only connections reject all edits.
- Aggregate results are read-only.
- A result showing more than one table cannot have rows inserted (but can update/delete from individual tables).
- Staged edits are ordered: deletes → inserts → updates.
- Only explicit refresh reruns the query; staged edits persist across local view changes.
Usage
Use this principle when a database tool lets users edit data through query results: trace columns to tables, generate DML for review, and apply transactionally with cancellation safety.
Theoretical Basis
The principle follows a stage-plan-review-apply pipeline:
- Stage: The grid UI sends cell changes as
Changes { updates, deletes, inserts }. Cell values are either literals (Edit::Text) or SQL expressions (Edit::Sql). - Plan:
sql_plangenerates DML from the changes using the result'sSource::Tablesmetadata. DELETE locates rows by key. INSERT uses RETURNING/OUTPUT/read-back. UPDATE sets columns by key. - Review: The generated SQL is shown to the user for approval.
- Apply:
Backend::applyruns the approved statements transactionally. Cancellation must not interrupt a commit. INSERT RETURNING rows are stashed for the next query run.
# Abstract pattern (NOT real implementation):
def plan(result, changes) -> list[str]:
source = result.source # Source::Tables or not editable
statements = []
for row in changes.deletes:
statements.append(f"DELETE FROM {table} WHERE {locate(row)}")
for cells in changes.inserts:
statements.append(f"INSERT INTO {table} ({cols}) VALUES ({vals}) RETURNING *")
for row, cells in changes.updates:
statements.append(f"UPDATE {table} SET {sets} WHERE {locate(row)}")
return statements # user reviews before apply