@ocap/statedb-sqlite
v1.30.10
Published
OCAP statedb adapter that uses SQLite as backend
Downloads
1,851
Readme
@ocap/statedb-sqlite
OCAP statedb adapter that uses SQLite as backend via Kysely
Install
npm install @ocap/statedb-sqlite
// or
bun install @ocap/statedb-sqliteUsage
In-Memory Mode
For testing or ephemeral data:
const SqliteStateDB = require('@ocap/statedb-sqlite').default;
const statedb = new SqliteStateDB({ filename: ':memory:' });
await statedb.initialize();
// Use statedb...
await statedb.account.create('z1abc...', { balance: '1000' });
// Close when done
await statedb.close();File Mode
For persistent storage:
const SqliteStateDB = require('@ocap/statedb-sqlite').default;
const statedb = new SqliteStateDB({ filename: '/path/to/statedb.sqlite' });
await statedb.initialize();
// Data persists across restartsFeatures
- WAL mode enabled by default for better concurrent read performance
- Automatic migrations on initialization
- Transaction support via
runAsLambda() - All 13 state tables: account, asset, token, factory, stake, delegation, rollup, etc.
API
Constructor Options
interface SqliteStateDBOptions {
filename: string; // ':memory:' or file path
}Methods
initialize()- Run migrations and prepare databaseclose()- Close database connectionrunAsLambda(fn)- Execute function within a transaction
