@keyv/sqlite
SQLite storage adapter for Keyv
SQLite storage adapter for Keyv.
Install
npm install --save keyv @keyv/sqlite
Usage
import Keyv from 'keyv';
import KeyvSqlite from '@keyv/sqlite';
const keyv = new Keyv(new KeyvSqlite('sqlite://path/to/database.sqlite'));
keyv.on('error', handleConnectionError);
You can specify the table, busyTimeout, and wal options.
e.g:
import Keyv from 'keyv';
import KeyvSqlite from '@keyv/sqlite';
const keyvSqlite = new KeyvSqlite('sqlite://path/to/database.sqlite', {
table: 'cache',
busyTimeout: 10000,
wal: true // Enable WAL mode for better concurrency
});
const keyv = new Keyv({ store: keyvSqlite });
Options
uri- The SQLite database URI (default:'sqlite://:memory:')table- The table name to use for storage (default:'keyv')busyTimeout- Sets a busy handler that sleeps for a specified amount of time when a table is lockedwal- Enable Write-Ahead Logging mode for better concurrency and performance (default:false)- Note: WAL mode is not supported for in-memory databases (
:memory:). A warning will be logged and the option will be ignored.
- Note: WAL mode is not supported for in-memory databases (
keySize- The maximum key size in bytes (default:255, max:65535)
You can also use a helper function to create Keyv with KeyvSqlite store.
import {createKeyv} from '@keyv/sqlite';
const keyv = createKeyv('sqlite://path/to/database.sqlite');