Skip to content

WithBroadcaster: publish committed row changes - #46

Merged
djthorpe merged 5 commits into
masterfrom
djt/1118/broadcaster
Nov 18, 2026
Merged

djthorpe merged 5 commits into
masterfrom
djt/1118/broadcaster

Conversation

@djthorpe

@djthorpe djthorpe commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Rows which are written are published to a broadcaster, such as go-server's broadcaster.Broadcaster, once they're committed, like go-pg's pgbroadcaster, but without a Publish call or triggers. SQLite has no NOTIFY, so the writer's hooks say what's written.

  • sqlite.WithBroadcaster(b, tables...): a Publisher, with a non-blocking Publish(schema.Change) int, and the tables which are published, or all of them.
  • A change is go-server's schema.Change: its action, create, update or delete, its database, main, its table, and its rowid, as Row.
  • The hooks: the writer's pre-update hook records each row, and its commit and rollback hooks keep, or forget, them. The pre-update hook, rather than the update hook, sees DELETE without a WHERE, rows which INSERT OR REPLACE replaces, and rows which a foreign key's cascade deletes.
  • Committed: changes are published after the commit, before the writer is released, so a watcher, reading on its own goroutine, reads what changed. A commit which fails, and is rolled back, publishes nothing.
  • Savepoints: SQLite doesn't say when one is rolled back to, so Tx within a transaction, and a query of several statements, mark where theirs start, and forget the rows after it. The rows are forgotten before the savepoint is released, which commits it, outside of a transaction.
  • Once per row: a row written several times in a transaction is one change: created and deleted is none, deleted and created again is updated. A row whose rowid changes is deleted and created.
  • Many rows: more than sqlite.MaxChanges (1000) rows of a table, in a transaction, are one change of the table, without a row.
  • Shadow tables, such as fts5's, aren't published, of pragma_table_list.
  • Not seen: writes by other processes, tables WITHOUT ROWID, and savepoints written by hand in SQL, whose rolled-back rows are still published.
  • README: a Changes section.

djthorpe and others added 2 commits November 18, 2026 15:02
…mmitted, of the writer's pre-update, commit and rollback hooks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 14:03
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Coverage for this change: 90.6%

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@djthorpe djthorpe self-assigned this Nov 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved transaction-tracking defects can publish notifications for rolled-back rows or silently discard committed notifications, including when a dedicated reader rolls back.

5 open issues
What changed in this PR

Adds opt-in broadcasting of committed row changes to the ncruces SQLite driver, allowing watchers to receive notifications without triggers or explicit publish calls.

Changes:

  • Introduces WithBroadcaster, a publisher interface, and a per-table notification threshold.
  • Adds hook-based change tracking, row merging, savepoint handling, and shadow-table filtering.
  • Documents the feature and adds tests for transactions, cascades, table filtering, and committed reads.
File Description
README.md Documents broadcasting usage, guarantees, and limitations.
opts.go Defines broadcaster options, Publisher, and MaxChanges.
ncruces/​pool.go Installs writer hooks and flushes notifications before releasing the writer.
ncruces/​fts5/​fts5_test.go Tests exclusion of FTS5 shadow-table changes.
ncruces/​exec.go Adds change-tracking marks for multi-statement savepoints.
ncruces/​conn.go Integrates tracking with query execution and nested transactions.
ncruces/​changes.go Implements change collection, merging, filtering, and publication.
ncruces/​changes_test.go Tests notifications across writes, rollbacks, cascades, and committed reads.

Review effort: Balanced

Comment thread ncruces/changes.go Resolved
Comment thread ncruces/conn.go Resolved
Comment thread ncruces/exec.go Resolved
Comment thread ncruces/changes.go Resolved
Comment thread ncruces/changes.go Resolved
…nts are checked, readers don't change the writer's changes, table types are read of each flush, and tables WITHOUT ROWID aren't published

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@djthorpe
djthorpe merged commit 399a232 into master Nov 18, 2026
2 checks passed
@djthorpe
djthorpe deleted the djt/1118/broadcaster branch November 18, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants