Documentation
¶
Overview ¶
Package sqlite is the built-in SQLite dialect for the msgin sql adapter engine (github.com/kartaladev/msgin/adapter/database/sql). It implements the engine's lease/claim source SPI (LeaseDialect) and the dedup-inbox SPI (InboxDialect); pass sqlite.LeaseDialect() to NewPollingSource/ NewOutboundAdapter and sqlite.InboxDialect() to NewInboxDeduper.
Driver ¶
This module imports no driver — the caller opens the *sql.DB. The recommended driver is modernc.org/sqlite (pure-Go, cgo-free), which bundles SQLite >=3.45 and satisfies this dialect's floor: RETURNING (>=3.35), ON CONFLICT (>=3.24), and unixepoch('now','subsec') (>=3.42). The DSN builder below emits modernc-flavored pragmas; other drivers need their own DSN.
Delivery guarantee ¶
At-least-once, identical to the postgres/mysql dialects. SQLite serializes writers (a single database-wide write lock), so there is no lock/FOR UPDATE strategy: sqlite.LeaseDialect() does NOT implement LockDialect, and WithStrategy(StrategyLockForUpdate) with it returns ErrLockStrategyUnsupported. A worker pool still runs, but write operations serialize; throughput is bounded by the single writer.
Connection configuration (important) ¶
Because writers serialize, concurrent consumers (multiple pollers, or a worker pool acking/nacking in parallel) MUST use WAL journal mode and a non-zero busy_timeout, or they fail with SQLITE_BUSY under contention. Use DSN to build a connection string with those defaults, e.g.:
dsn := sqlite.DSN("/var/lib/app/msgin.db")
// file:/var/lib/app/msgin.db?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)
db, err := sql.Open("sqlite", dsn) // caller imports modernc.org/sqlite
src, err := msginsql.NewPollingSource(db, "queue", sqlite.LeaseDialect())
Schema ¶
Timestamp columns are INTEGER epoch microseconds written from SQLite's own clock. Provision the schema with the reference DDL (see DDL / InboxDDL) or EnsureSchema; msgin never runs DDL implicitly on the production path.
Index ¶
- func DDL(table string) (string, error)
- func DSN(path string, opts ...DSNOption) string
- func GroupDDL(table string) (string, error)
- func GroupDialect() msginsql.GroupDialect
- func InboxDDL(table string) (string, error)
- func InboxDialect() msginsql.InboxDialect
- func LeaseDialect() msginsql.LeaseDialect
- type DSNOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DDL ¶
DDL returns the reference CREATE TABLE (+ claim index) for the lease/claim schema on SQLite, for callers to fold into their migration tool. It validates table before building; msgin never runs it on the production path (ADR 0010 D2).
func DSN ¶
DSN builds an opinionated, overridable modernc.org/sqlite connection string for path (a filesystem path; DSN prepends the file: URI scheme). The default enables WAL journal mode and a 5s busy_timeout so concurrent consumers serialize on the single writer instead of failing with SQLITE_BUSY (see the package doc for why both are required). DSN imports no driver — it only assembles a string; the caller opens the *sql.DB with their chosen driver. For DSNs more exotic than these options cover, construct the string yourself.
A nil element in opts is ignored — DSN returns a string and has no error to return, so there is nowhere to report the fault (Spec 015 §3.3). The skip is therefore SILENT, and the cost is the caller's to avoid: the resulting DSN carries msgin's defaults for whatever the dropped option would have set — WAL journal mode, a 5s busy_timeout, and a file-backed database — so a dropped WithJournalMode("") silently keeps WAL rather than omitting the pragma, a dropped WithBusyTimeout silently keeps 5s, and a dropped WithSharedMemory silently targets a different database (a file instead of the shared in-memory one). The returned string looks valid and opens fine either way, so build the option unconditionally rather than relying on this. Every non-nil element still applies, whether it sits before or after the nil one. (A nil opts SLICE — DSN(path) or DSN(path, nils...) — is a normal zero-option call, unaffected.)
func GroupDDL ¶
GroupDDL returns the reference CREATE TABLE statements (group-lease table + member table + supporting indexes) for the durable Aggregator group store on SQLite, for callers to fold into their own migration tool. It validates table (ErrInvalidTableName on a bad identifier) as the sole entry point — there is no string-returning DDL method on the GroupDialect interface to bypass validation (ADR 0021 §3). msgin never runs this on the production path.
func GroupDialect ¶
func GroupDialect() msginsql.GroupDialect
GroupDialect returns the built-in SQLite GroupDialect. Pass it as the required dialect argument to msginsql.NewGroupStore. Its multi-statement operations run on a dedicated *sql.Conn with BEGIN IMMEDIATE, so a *sql.DB (not a *sql.Tx) must back the store (ADR 0021 §3, M-D).
func InboxDDL ¶
InboxDDL returns the reference CREATE TABLE (+ retention index) for the dedup-inbox schema on SQLite (ADR 0010 D10). It validates table as the sole entry point (no string-returning DDL method on the SPI).
func InboxDialect ¶
func InboxDialect() msginsql.InboxDialect
InboxDialect returns the built-in SQLite InboxDialect — the same stateless value as LeaseDialect(), narrowed to the dedup-inbox SPI. Pass it to NewInboxDeduper.
func LeaseDialect ¶
func LeaseDialect() msginsql.LeaseDialect
LeaseDialect returns the built-in SQLite LeaseDialect (lease/claim strategy). Pass it as the required dialect argument to NewPollingSource/ NewOutboundAdapter. It does NOT implement LockDialect (sqlite is lease-only).
Types ¶
type DSNOption ¶
type DSNOption func(*dsnConfig)
DSNOption customizes the DSN produced by DSN.
func WithBusyTimeout ¶
WithBusyTimeout overrides the busy_timeout pragma (default 5s), emitted in milliseconds. A zero (or negative) duration omits the pragma — do this only if you accept SQLITE_BUSY errors under write contention (see package doc).
func WithJournalMode ¶
WithJournalMode overrides the journal_mode pragma (default "WAL"). An empty mode omits the pragma entirely. Ignored under WithSharedMemory (WAL is meaningless for an in-memory database).
func WithSharedMemory ¶
func WithSharedMemory() DSNOption
WithSharedMemory targets an in-memory database shared across the pool (file::memory:?cache=shared) instead of a file; the path argument to DSN is ignored. Intended for ephemeral/testing use — the database vanishes when the last connection closes.