Documentation
¶
Overview ¶
Package sqlite provides SQLite-backed implementations of refid.SequenceStore (via NewSequence) and refid.RandomStore (via NewRandom) using database/sql and raw SQL — no ORM. Import a SQLite driver (e.g. modernc.org/sqlite, which is pure Go — no CGO), open a connection with sql.Open, and pass the resulting *sql.DB to NewSequence or NewRandom.
SQLite allows only one writer at a time via a whole-database file lock, and nothing sets a busy_timeout by default, so concurrent access can fail immediately with SQLITE_BUSY. Set a busy timeout in the DSN (e.g. "file:refid.db?_busy_timeout=5000") if you need Next to wait instead of failing, or use refid/store/postgres for real concurrent-safe access.
Index ¶
- Constants
- func MigrateRandom(ctx context.Context, db *sql.DB, opts ...Option) error
- func MigrateSequence(ctx context.Context, db *sql.DB, opts ...Option) error
- func NewRandom(db *sql.DB, opts ...Option) (refid.RandomStore, error)
- func NewSequence(db *sql.DB, opts ...Option) (refid.SequenceStore, error)
- type Option
Constants ¶
const DefaultRandomTableName = "refid_random"
DefaultRandomTableName is the default table name used for issued random ID values.
const DefaultSequenceTableName = "refid_sequences"
DefaultSequenceTableName is the default table name used for sequence counters.
Variables ¶
This section is empty.
Functions ¶
func MigrateRandom ¶ added in v0.2.0
MigrateRandom creates the issued-random-value table if it does not already exist. Pass WithTableName to migrate a custom table name.
func MigrateSequence ¶ added in v0.2.0
MigrateSequence creates the sequence-counter table if it does not already exist. Pass WithTableName to migrate a custom table name.
func NewRandom ¶ added in v0.2.0
NewRandom returns a refid.RandomStore backed by SQLite. db must already be opened against the sqlite driver (see the package doc). By default it targets the "refid_random" table; override with WithTableName. NewRandom returns an error (never panics) if an option is invalid.
func NewSequence ¶ added in v0.2.0
NewSequence returns a refid.SequenceStore backed by SQLite. db must already be opened against the sqlite driver (see the package doc). By default it targets the "refid_sequences" table; override with WithTableName. NewSequence returns an error (never panics) if an option is invalid.
Types ¶
type Option ¶
type Option func(*config)
Option configures optional behavior for a SQLite SequenceStore or RandomStore.
func WithTableName ¶
WithTableName overrides the default table name ("refid_sequences" for NewSequence/MigrateSequence, "refid_random" for NewRandom/MigrateRandom). An invalid name (must match [a-zA-Z_][a-zA-Z0-9_]*) is recorded and surfaced as an error from the constructor or migrate function — never a panic.