feat(refid): add raw-SQL sqlite backend - #177
Open
sthanikan2000 wants to merge 2 commits into
Open
Conversation
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>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
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.
Summary
github.com/OpenNSW/core/refid/sqlite, mirroringrefid/postgres's exact shape (DefaultTableName,Option,WithTableName,New,Migrate,Reserve/Commit/Rollback) viadatabase/sql+ the pure-Gomodernc.org/sqlitedriver — no CGO.Storeescape 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/postgreskeeps working unchanged throughout. Base is set torefactor/refid-store-interface, notmain, since this depends on that PR'sStore/Reservationredesign; retarget tomainonce #176 merges.Test plan
go build ./...,go vet ./...,golangci-lint run ./...all clean inrefid/go test -race ./...passes inrefid/, including SQLite's own commit-conflict test and a 50-goroutine concurrent-retry test exercising the compare-and-swapCommitpath?1/?2/?3) work withmodernc.org/sqlite, letting the compare-and-swap query reuse?2acrossVALUESandSETexactly like postgres's$2🤖 Generated with Claude Code