kvslite
v1.0.4
Published
Synchronous key-value store in node using sqlite3 and v8's serialization. Holds arbitrary data.
Downloads
5
Readme
kvslite
Synchronous persistent key-value store for node using sqlite3
and v8's serialize & deserialize. No daemon!
npm i kvslite
- ✅ Store any data including classes, sets, etc
- ✅ Add 100k records per second
- ✅ Use in memory or on drive
- better-sqlite3 seems to require node version 16
example
import { KVS } from 'kvslite'
type User = { id: string; name: string }
const users = new KVS()<User>('mydb.db')
const memoryDb = new KVS(':memory:')
db.set('key', 'value')
db.set('objectsAllowed', new Date())
db.set('yepThisWorks', { big: { complicated: { object: new Set() } } })
API
new KVS<T>(filepath, collectionName?)
: Make or open a collection. One path can hold multiple collections.db.close()
: Close the filedb.set(key, value)
: Set or update key to valuedb.get(key): T?
: Get value by keysetMany(mapping: Record<string, T>)
: Set many values in one transaction, aborting if any failgetMany(keys: string[]): Record<string, T>?
: Get many values, returns undefined if any keys are absentdb.delete(key)
: Delete key if it existsdb.all(): Record<string, T>?
: Get all keys and valuesdb.find(prefix): Record<string, T>?
: Get values for all keys starting with prefix