SQLite Storage
SqliteStorage persists key-value data to a local SQLite database file. It requires thebetter-sqlite3 package and is ideal for single-node deployments, embedded applications, or lightweight production setups.
Installation
Native module note
Native module note
better-sqlite3 is a native Node.js addon. If you encounter build errors, ensure you have build tools installed (e.g., node-gyp, Python, Visual Studio Build Tools on Windows).Setup
Constructor
Path to the SQLite database file. The file is created if it doesn’t exist. Use
:memory: for an in-process in-memory database (still uses SQLite, but no disk).Full Example
Schema
SqliteStorage creates a single tablekv_store:
| Column | Type | Description |
|---|---|---|
namespace | TEXT | Namespace (e.g., memory:short, session) |
key | TEXT | Key within the namespace |
value | TEXT | JSON-serialized value |
updated_at | TEXT | Last update timestamp |
(namespace, key). WAL mode is enabled for better concurrent read performance.
Prefix Listing
Graceful Shutdown
API Reference
| Method | Description |
|---|---|
get<T>(namespace, key) | Get value. Returns null if not found. |
set<T>(namespace, key, value) | Store value (JSON-serialized). Upserts on conflict. |
delete(namespace, key) | Remove key. |
list<T>(namespace, prefix?) | List keys. Prefix uses SQL LIKE pattern. |
close() | Close the database connection. |