Principle:2giosangmitom Sqmeow nvim Transactional Apply
| Knowledge Sources | |
|---|---|
| Domains | Editing, Cancellation |
| Last Updated | 2026-10-16 14:00 GMT |
Overview
A transactional application principle that executes approved DML statements atomically, with cancellation safety ensuring that cancelled writes report their actual outcome rather than an assumed rollback.
Description
Transactional Apply is the principle of running planned DML statements as a unit where the dialect supports transactions, and reporting the outcome honestly. Cancellation must not interrupt a commit: Cancelled means no changes were committed (for transactional dialects). Adapters without transactions report partial application as a driver error, so callers do not mistake partial writes for a complete rollback.
This principle addresses the challenge of safely applying edits with cancellation support: a user may cancel mid-apply, but a write already sent to the database may have committed. The adapter must report the actual outcome — a sent write's success is observed even after cancel. The await_sent helper ensures a sent non-transactional write keeps its success after cancel; cancellation stops the next write, not the observation of this one's outcome.
For non-transactional dialects (Redis, MongoDB, Scylla), cancelled_after(done, total) reports how many changes were applied before the rest were cancelled, so the user knows the partial state.
Usage
Use this principle when applying edits to a database: wrap in a transaction where supported, report actual outcomes on cancellation, and never assume rollback for non-transactional backends.
Theoretical Basis
The principle separates sent-write observation from cancellation:
- Transaction: Where the dialect supports transactions, statements run in a single transaction. Cancellation before commit means nothing was applied; cancellation during commit reports the actual outcome.
- Non-transactional: Each statement runs independently. A sent write's outcome is observed even after cancel. The helper
cancelled_after(done, total)reports partial application. - Deadline: A
Deadlinetrips the cancel token aftertimeout_ms. If the deadline (not a user cancel) tripped, the error says "ran past the timeout."
# Abstract pattern (NOT real implementation):
async def apply(statements, cancel_token):
if dialect_supports_transactions:
return await transactional_execute(statements, cancel_token)
else:
done = 0
for stmt in statements:
if cancel_token.cancelled: return cancelled_after(done, len(statements))
await execute(stmt) # observe outcome even if cancelled during
done += 1
return all_results
# A sent write keeps its success after cancel:
async def await_sent(cancel, work):
if cancel.is_cancelled: raise Cancelled # before send
return await work # observe outcome even if cancelled during
Related Pages
Implemented By
- Implementation:2giosangmitom_Sqmeow_nvim_Core_plan_apply
- Implementation:2giosangmitom_Sqmeow_nvim_Deadline