Add :read-only option to init-db! - #22
Open
sundbp wants to merge 1 commit into
Open
Conversation
sundbp
force-pushed
the
init-db-read-only
branch
from
August 17, 2026 16:20
9c0cdea to
3aa68a5
Compare
Every connection, the writer pool included, opens with SQLITE_OPEN_READONLY when :read-only is true, so writes through any connection fail at the SQLite level. Read-only connections skip the :journal_mode and :page_size pragmas: setting either can require a database header write (WAL conversion, page size on an empty database), which fails on a read-only connection. This also lets the existing read-only reader pool open rollback-journal databases, which previously failed during pool construction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Read-only tooling (reports, reconciliation jobs, migration linters) wants a hard mechanical guarantee that nothing can write to a live database. Today
init-db!always opens the writer pool withSQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, so a caller that never issues writes is only safe by convention, and passing{:read-only true}toinit-db!is silently ignored.Change
init-db!accepts a top-level:read-onlyoption. When true, every connection — the writer pool included — opens withSQLITE_OPEN_READONLY, so writes through any connection fail at the SQLite level.:journal_modeand:page_sizepragmas: setting either can require a database header write (WAL conversion, page size on an empty database), which fails on a read-only connection. This also fixes a pre-existing limitation: the read-only reader pool could not open a rollback-journal database because the defaultjournal_mode=WALpragma threw during pool construction.pragma->set-pragma-querygains a 2-arity that takes the read-only flag; the existing 1-arity is unchanged.Verification
bb test: 21 tests, 78 assertions, 0 failures (two new tests: read-write rejection through the read-only writer pool, and read-only open of a rollback-journal database).