Turso Database Adds Trigger-Free CDC for SQLite
Brief
Turso Database’s built-in CDC records SQLite row changes without per-table triggers. The article also outlines a restart-safe polling consumer and the feature’s operational constraints.
How capture works
- Run
PRAGMA capture_data_changes_conn('full')on each write connection to record inserts, updates, and deletes inturso_cdc. - Records include ordered change IDs, transaction IDs, change types, and row images; changes appear only after commit, with a COMMIT record closing each transaction group.
- Capture modes range from primary-key-only
idtofull, which includes before and after images plus per-column update details.
Building a restart-safe consumer
- Poll changes in batches, group them by transaction, and apply a group only when its COMMIT record arrives; continue reading until caught up, including when a transaction spans batches.
- Store a consumer watermark and advance it only when no transaction groups remain open. A crash may replay an already-applied transaction, so make
applyidempotent. - Prune
turso_cdcusing the slowest consumer’s watermark; on synced databases, cleanup could delete changes that Sync has not pushed yet.
Constraints and uses
- Capture is per connection, so every write connection must enable it. The change table grows until pruned, and decoding uses the current schema, which can mis-map older records after columns are dropped.
- The article highlights cache and search-index synchronization, audit trails, and per-database feeds for centralized analytics as use cases.
Generated by AI from the original article. Check the source for full details.