SQLR-10 — honor CREATE TABLE IF NOT EXISTS + queryable sqlrite_master + PRAGMA table_list#151
Merged
Merged
Conversation
…yable
Two engine ergonomics gaps that every embedding SDK consumer hits when
writing idempotent "run my schema on startup" migrations:
1. `CREATE TABLE IF NOT EXISTS` was parsed but ignored — a second create
of an existing table errored "table already exists", unlike
`CREATE INDEX IF NOT EXISTS`. Now `CreateQuery` carries the
`if_not_exists` flag and the executor treats a re-create as a no-op
(by name only; no schema diff, matching SQLite).
2. The schema catalog wasn't reachable from SQL. Added:
- `SELECT … FROM sqlrite_master` — synthesizes a read-only in-memory
catalog table on demand (type/name/sql/rootpage/last_rowid), reusing
the same SQL synthesis the persistence path uses. Works through the
normal single-table SELECT path (WHERE/projection/ORDER BY/LIMIT);
reflects live in-memory state. Writes remain rejected; joins against
it are out of scope.
- `PRAGMA table_list` — SQLite-canonical lightweight introspection
(schema/name/type/ncol/wr/strict) listing tables + sqlrite_master.
Covers the REPL and every SDK (all route through execute_select_rows /
process_command). Docs (supported-sql.md, README) updated; the
go-collector example's now-stale workaround comments refreshed.
Tests: parser flag capture; IF NOT EXISTS idempotency + still-errors
without it + fresh-create; sqlrite_master listing/filtering/SELECT */
write-rejection/save-reopen; PRAGMA table_list listing + value-rejection.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
What & why
Two engine ergonomics gaps surfaced while building the SQLR-43 Go collector (
examples/go-collector) — both hit by any embedding SDK consumer writing idempotent "run my schema on every startup" migrations.1.
CREATE TABLE IF NOT EXISTSis now honoredPreviously the clause was parsed but ignored, so a second
CREATE TABLE IF NOT EXISTS t (...)against an existing table erroredCannot create, table already exists.— breaking reopen-and-migrate.CreateQuerynow carries theif_not_existsflag and the executor treats a re-create as a no-op (by name only — no schema diff, matching SQLite and the existingCREATE INDEX IF NOT EXISTS). PlainCREATE TABLEon an existing table still errors.2. The catalog is now reachable from SQL
SELECT … FROM sqlrite_master— synthesizes a read-only in-memory catalog table on demand (columnstype, name, sql, rootpage, last_rowid), reusing the exact SQL synthesis the persistence path uses. Runs through the normal single-table SELECT path, soWHERE/ projections /ORDER BY/LIMITall work. Reflects live in-memory state. Writes are rejected; joins against it are out of scope.rootpageis0in this live view (pages are assigned at save time).PRAGMA table_list— SQLite-canonical lightweight introspection (schema, name, type, ncol, wr, strict), listing user tables +sqlrite_master.Both reach the REPL and every SDK — the public
Statement::query()path and the REPL both route throughexecute_select_rows/process_command.Tests
9 new tests, all failing on the unfixed code:
sqlrite_masterlisting /typefiltering /SELECT *schema / write-rejection / save→reopen persistencePRAGMA table_listlisting + value-rejectionFull workspace suite green (604 engine tests),
cargo fmt --checkclean, no new clippy/doc warnings.Docs
docs/supported-sql.md(CREATE TABLE IF NOT EXISTS, a "Querying the catalog" section,PRAGMA table_list),README.mdSQL-feature table, and the go-collector example's now-stale workaround comments refreshed.🤖 Generated with Claude Code