Skip to content

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

Open
sthanikan2000 wants to merge 1 commit into
refactor/refid-raw-sql-postgresfrom
feat/refid-sqlite-store
Open

feat(refid): add raw-SQL sqlite backend#181
sthanikan2000 wants to merge 1 commit into
refactor/refid-raw-sql-postgresfrom
feat/refid-sqlite-store

Conversation

@sthanikan2000

@sthanikan2000 sthanikan2000 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds refid/store/sqlite, a second refid.SequenceStore implementation using the pure-Go modernc.org/sqlite driver (no CGO). Same shape as refid/store/postgres: DefaultTableName, Option, WithTableName, New, Migrate, single atomic upsert-and-increment Next.
  • SQLite only allows one writer at a time (whole-database file lock, not per-row like Postgres), so New guards Next with an in-process sync.Mutex rather than touching the caller's *sql.DB connection-pool configuration. The package doc's "Concurrency" section spells out exactly what that mutex covers (calls through one SequenceStore instance in one process) and what it doesn't (a second connection/process sharing the same file — configure SQLite's busy_timeout for that).
  • Useful on its own as a convenient refid.SequenceStore for local dev and tests, in addition to being a real second backend.
  • Stacked on refactor(refid)!: replace gorm-based postgres store with raw SQL under refid/store/postgres #180 (raw-SQL postgres, itself stacked on revert: refactor(refid)!: rename SequenceStore to Store, replace gorm postgres backend with raw SQL #179 the revert) — so this diffs cleanly against a SequenceStore-named, refid/store/postgres-shaped main once both merge in order.

Test plan

  • go build ./..., go vet ./..., golangci-lint run clean
  • go test -race ./... — increment, overflow-freezes-counter, invalid-table-name-returns-error-not-panic, 50-goroutine no-duplicates, and a regression test proving Next fails promptly (not hangs) when another transaction on the same *sql.DB holds SQLite's write lock
  • Pre-push hook's full monorepo go test -race ./... passes

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 2, 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: 92fd3874-041e-4ce7-be9b-b446291424df

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.

Adds a SQLite-backed refid.SequenceStore implementation using the
pure-Go modernc.org/sqlite driver (no CGO), alongside the existing
PostgreSQL backend. Same shape: DefaultTableName, Option,
WithTableName, New, Migrate, and a single atomic upsert-and-increment
statement for Next.

SQLite only allows one writer at a time via a whole-database file
lock, so New guards Next with an in-process mutex rather than mutating
the caller's *sql.DB connection-pool configuration. That mutex only
serializes calls made through one Store instance in one process — see
the package doc's "Concurrency" section for exactly what it does and
doesn't cover, and how to configure SQLite's busy_timeout for the
cases it doesn't (a second connection/process sharing the same file).

Useful standalone for local development and tests as a convenient
refid.SequenceStore, in addition to being a second real backend.
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