Skip to content

feat(refid): add raw-SQL sqlite backend - #177

Open
sthanikan2000 wants to merge 2 commits into
refactor/refid-store-interfacefrom
feat/refid-raw-sql-backends
Open

feat(refid): add raw-SQL sqlite backend#177
sthanikan2000 wants to merge 2 commits into
refactor/refid-store-interfacefrom
feat/refid-raw-sql-backends

Conversation

@sthanikan2000

Copy link
Copy Markdown
Collaborator

Summary

  • Adds github.com/OpenNSW/core/refid/sqlite, mirroring refid/postgres's exact shape (DefaultTableName, Option, WithTableName, New, Migrate, Reserve/Commit/Rollback) via database/sql + the pure-Go modernc.org/sqlite driver — no CGO.
  • Documents the SQLite backend and the bring-your-own-Store escape hatch in the README.

Why

A pure-Go SQLite option avoids imposing a CGO build requirement on every downstream service for an optional backend (a real cost for cross-compilation and minimal/distroless Docker images), and gives local development and tests a real, on-disk backend with no external service dependency — SQLite's tests run unconditionally in-process, unlike the Postgres backend's POSTGRES_TEST_DSN-gated integration test.

This PR is purely additive on top of #176 (stacked on that branch) — refid/postgres keeps working unchanged throughout. Base is set to refactor/refid-store-interface, not main, since this depends on that PR's Store/Reservation redesign; retarget to main once #176 merges.

Test plan

  • go build ./..., go vet ./..., golangci-lint run ./... all clean in refid/
  • go test -race ./... passes in refid/, including SQLite's own commit-conflict test and a 50-goroutine concurrent-retry test exercising the compare-and-swap Commit path
  • Confirmed native SQLite numbered placeholders (?1/?2/?3) work with modernc.org/sqlite, letting the compare-and-swap query reuse ?2 across VALUES and SET exactly like postgres's $2

🤖 Generated with Claude Code

sthanikan2000 and others added 2 commits September 1, 2026 09:44
Adds github.com/OpenNSW/core/refid/sqlite, mirroring the postgres
backend's exact shape (DefaultTableName, Option, WithTableName, New,
Migrate, Reserve/Commit/Rollback with the same read-then-compare-and-
swap-write logic) via database/sql + the pure-Go modernc.org/sqlite
driver (no CGO) — a lighter build/deploy footprint than a CGO-based
driver for a shared library consumed by many services.

Dialect differences from postgres: SQLite's upsert grammar uses
unqualified column names in DO UPDATE (no table-name qualification),
no TIMESTAMPTZ (created_at is TEXT via datetime('now')), and one
integer affinity covers int64 (no separate BIGINT). Uses SQLite's
native numbered placeholders (?1/?2/?3) so the compare-and-swap query
can reuse ?2 across VALUES and SET, same as postgres's $2.

Unlike postgres's POSTGRES_TEST_DSN-gated integration test, sqlite's
tests open a real on-disk file via t.TempDir() and run unconditionally
in-process — no service container needed.

go.mod: adds modernc.org/sqlite as a new direct dependency.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds the SQLite subsection to Database Setup and updates the Features
bullet to mention both bundled backends.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: b9533b36-d458-45f3-bb9d-cce7473fa188

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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