Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
SQLite Atomic Transaction (Commit / Rollback)
Execute multiple database mutations inside an atomic transaction block.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Database). Copy the parameterized template or run the self-contained example.
- 1Category: Database
- 2Attribution: Otter Core Language Spec (D97, D98)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
begin transaction on ${db} into ${tx}
execute ${tx} with
"${sqlMutation}"
commit ${tx}
database has
provider is "sqlite"
connection is ":memory:"
.
connect database into memDb
execute memDb with
"create table balances (account text primary key, balance real)"
execute memDb with
"insert into balances (account, balance) values ('ACC-1', 500)"
begin transaction on memDb into tx
execute tx with
"update balances set balance = balance - 50 where account = 'ACC-1'"
commit tx
query memDb with
"select balance from balances where account = 'ACC-1'"
into rows
row is first of rows
say "Committed balance:" balance of row
if balance of row is not 450
fail with "transaction balance mismatch: expected 450"
.
Installation & Usage
otter snippet inspect db-sqlite-transaction
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.