Registry / database / bun-sqlite-key-value

bun-sqlite-key-value

JSON →
library1.13.1jsnpmunverified

bun-sqlite-key-value is a high-performance key-value store (v1.13.1) built on bun:sqlite, optimized for Bun runtime with V8 serialization as a faster JSON alternative. It offers 3-5x speed improvement over other Node.js key-value stores by leveraging Bun's native SQLite bindings and a custom serialization format. Released actively, it provides a simple API for caching and persistent storage with automatic schema management and optional TTL support. It ships with TypeScript types and requires no external SQLite driver, making it a lean choice for Bun projects needing a fast local KV store.

npm install bun-sqlite-key-value
INSTALL
IMPORT
SIG · BUN-SQLITE-KEY-VAL
B
bun-sqlite-key-value
databasejavascriptv1.13.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import KeyValue from 'bun-sqlite-key-value'
import { KeyValue } from 'bun-sqlite-key-value'
Package exports a default class. Named exports are incorrect.
BunSqliteKeyValue
import KeyValue from 'bun-sqlite-key-value'
const KeyValue = require('bun-sqlite-key-value')
CommonJS require is not supported; package is ESM-only.
KeyValueOptions
import type { KeyValueOptions } from 'bun-sqlite-key-value'
import { KeyValueOptions } from 'bun-sqlite-key-value'
This is a TypeScript type export; use import type to avoid bundling.

Demonstrates creating an in-memory key-value store, setting/getting objects, deleting a key, and closing the store.

import KeyValue from 'bun-sqlite-key-value'; const kv = new KeyValue({ path: ':memory:', ttl: 60000 }); await kv.set('user:1', { name: 'Alice', email: 'alice@example.com' }); await kv.set('user:2', { name: 'Bob' }); const alice = await kv.get('user:1'); console.log('Retrieved:', alice); await kv.delete('user:2'); const count = await kv.count(); console.log('Total entries:', count); await kv.close();
Debug
Known issues
gotchaKeys are case-sensitive; 'User:1' and 'user:1' are different entries.
fix
Use consistent key casing (e.g., lowercase with colons).
affects: >=0.0.0
gotchaSerialization uses V8 instead of JSON; only serializable values (plain objects, arrays, primitives) are supported.
fix
Avoid storing functions, Symbols, or non-serializable objects.
affects: >=0.0.0
gotchaThe `ttl` option removes entries on `get` if expired, but expired entries may persist if eviction happens only on read or write.
fix
Set a reasonable TTL and rely on periodic cleanup or explicit expiration checks.
affects: >=0.0.0
breakingVersion 1.0.0 changed the default export from a function that returns a new instance to a class constructor.
fix
Update from `const kv = KeyValue(...)` to `const kv = new KeyValue(...)`.
affects: <1.0.0
deprecatedSupport for Bun <0.5.0 (deprecated). Uses `bun:sqlite` API that requires Bun 0.5+.
fix
Upgrade Bun to v0.5.0 or later.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'bun-sqlite-key-value'
Package not installed or missing from node_modules.
fix
Run `bun add bun-sqlite-key-value` to install.
TypeError: kv.get is not a function
Using outdated import style (function call instead of `new`).
fix
Use `const kv = new KeyValue({ path: ':memory:' })`.
Error: ESM modules not supported in this environment
Running in Node.js without ESM support or using `require()`.
fix
Use `import` syntax and ensure Node version >= 12 or run with Bun.
Error: The operation `set` is not supported for `:memory:` databases
Incorrect database path or read-only mode.
fix
Use a file path or `:memory:` correctly. Check permissions.
Upgrade
Version history
1.13.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
1
Resources
bun-sqlite-key-value — npm install bun-sqlite-key-value · libregistry