SQLite Storage
SQLite is an embedded database stored in a single file. It is a good fit for:
- Local development and demos (no external database needed)
- Single-node deployments that still want persistence across restarts
- Lightweight persistence for CLI tools or small services
Requirements
This backend uses the github.com/mattn/go-sqlite3 driver, which requires CGO
(a C compiler). Make sure your environment can build CGO code.
Basic Configuration Example
Notes:
NewServiceaccepts a*sql.DB. The session service owns the DB and will close it inClose(). Do not close the DB twice.- For better concurrency on a single machine, consider enabling WAL mode
(e.g.
_journal_mode=WAL) and setting_busy_timeoutin your DSN.
Configuration Options
- TTL and cleanup:
WithSessionTTL,WithAppStateTTL,WithUserStateTTL,WithCleanupInterval - Retention:
WithSessionEventLimit - Persistence:
WithEnableAsyncPersist,WithAsyncPersisterNum - Soft delete:
WithSoftDelete(default is enabled) - Summaries:
WithSummarizer,WithAsyncSummaryNum,WithSummaryQueueSize,WithSummaryJobTimeout - Schema/DDL:
WithSkipDBInit,WithTablePrefix - Hooks:
WithAppendEventHook,WithGetSessionHook
Use Cases
| Scenario | Recommended Configuration |
|---|---|
| Local development | Default configuration with WAL mode |
| Single-node production | Configure TTL and enable WAL mode |
| CLI tools | Minimal configuration, single DB file |
| Testing | In-memory SQLite (:memory:) for isolation |
Notes
- CGO Required: The SQLite driver requires CGO. Make sure your build environment has a C compiler.
- WAL Mode: Enable WAL mode (
_journal_mode=WAL) for better concurrency. - Busy Timeout: Set
_busy_timeoutin DSN to handle concurrent access gracefully. - Single File: All data stored in a single file, easy to backup and migrate.