Skip to content

SQLR-10 — honor CREATE TABLE IF NOT EXISTS + queryable sqlrite_master + PRAGMA table_list#151

Merged
joaoh82 merged 1 commit into
mainfrom
sqlr-10-create-table-if-not-exists
Jun 1, 2026
Merged

SQLR-10 — honor CREATE TABLE IF NOT EXISTS + queryable sqlrite_master + PRAGMA table_list#151
joaoh82 merged 1 commit into
mainfrom
sqlr-10-create-table-if-not-exists

Conversation

@joaoh82
Copy link
Copy Markdown
Owner

@joaoh82 joaoh82 commented May 31, 2026

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 EXISTS is now honored

Previously the clause was parsed but ignored, so a second CREATE TABLE IF NOT EXISTS t (...) against an existing table errored Cannot create, table already exists. — breaking reopen-and-migrate. CreateQuery now 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 and the existing CREATE INDEX IF NOT EXISTS). Plain CREATE TABLE on 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 (columns type, name, sql, rootpage, last_rowid), reusing the exact SQL synthesis the persistence path uses. Runs through the normal single-table SELECT path, so WHERE / projections / ORDER BY / LIMIT all work. Reflects live in-memory state. Writes are rejected; joins against it are out of scope. rootpage is 0 in 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 through execute_select_rows / process_command.

Tests

9 new tests, all failing on the unfixed code:

  • parser flag capture; IF NOT EXISTS idempotency + still-errors-without-it + fresh-create
  • sqlrite_master listing / type filtering / SELECT * schema / write-rejection / save→reopen persistence
  • PRAGMA table_list listing + value-rejection

Full workspace suite green (604 engine tests), cargo fmt --check clean, no new clippy/doc warnings.

Docs

docs/supported-sql.md (CREATE TABLE IF NOT EXISTS, a "Querying the catalog" section, PRAGMA table_list), README.md SQL-feature table, and the go-collector example's now-stale workaround comments refreshed.

🤖 Generated with Claude Code

…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>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rust-sqlite Ready Ready Preview, Comment May 31, 2026 9:07pm

Request Review

@joaoh82 joaoh82 merged commit 05fd59c into main Jun 1, 2026
21 checks passed
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.

1 participant