Registry / database / applesauce-sqlite

applesauce-sqlite

JSON →
library6.0.0jsnpmunverified

A SQLite3 event database implementation for the Applesauce Nostr client library, providing persistent storage for Nostr events. Version 6.0.0 supports multiple SQLite backends: better-sqlite3 (Node.js), libsql (Turso), and native SQLite (Bun/Deno). It serves as a drop-in replacement for the default in-memory database, combining in-memory caching with SQLite persistence for optimal performance. Includes a built-in Nostr relay implementation. Released under MIT license. Key differentiator: full compatibility with applesauce-core, hybrid architecture, and support for major SQLite drivers.

npm install applesauce-sqlite
INSTALL
IMPORT
SIG · APPLESAUCE-SQLITE
A
applesauce-sqlite
databasejavascriptv6.0.0
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.

BetterSqlite3EventDatabase
import { BetterSqlite3EventDatabase } from 'applesauce-sqlite/better-sqlite3'
const { BetterSqlite3EventDatabase } = require('applesauce-sqlite/better-sqlite3')
Package is ESM-only; CommonJS require will fail.
LibsqlEventDatabase
import { LibsqlEventDatabase } from 'applesauce-sqlite/libsql'
import { LibsqlEventDatabase } from 'applesauce-sqlite'
Import from subpath 'libsql', not the root.
NativeEventDatabase
import { NativeEventDatabase } from 'applesauce-sqlite/native'
import { NativeEventDatabase } from 'applesauce-sqlite'
Import from subpath 'native'.

Creates a persistent SQLite-backed EventStore using better-sqlite3 and adds a Nostr event.

import { EventStore } from 'applesauce-core'; import { BetterSqlite3EventDatabase } from 'applesauce-sqlite/better-sqlite3'; const database = new BetterSqlite3EventDatabase('./events.db'); const eventStore = new EventStore(database); // Add a dummy Nostr event eventStore.add({ id: 'dummy', kind: 1, pubkey: 'a', created_at: Math.floor(Date.now() / 1000), content: 'Hello', tags: [], sig: 'b', } as any);
Debug
Known issues
breakingImport paths changed to subpath exports in v6. You must import from 'applesauce-sqlite/better-sqlite3', 'applesauce-sqlite/libsql', or 'applesauce-sqlite/native', not from the root package.
fix
Update imports to use the correct subpath for your chosen SQLite driver.
affects: 6.0.0
deprecatedThe root-level export 'Database' symbol is removed in v6. Use per-driver exports.
fix
Replace import with e.g. 'import { BetterSqlite3EventDatabase } from 'applesauce-sqlite/better-sqlite3''
affects: <6.0.0
gotchabetter-sqlite3 is a native module; it may require build tools (python3, make, g++) on some systems.
fix
Install build tools or use libsql instead if you cannot compile native modules.
affects: all
gotchaThe package is ESM-only. Using require() will throw 'ERR_REQUIRE_ESM'.
fix
Use dynamic import() or switch to ESM (type: 'module' in package.json).
affects: >=6.0.0
gotchaUsing ':memory:' for better-sqlite3 will create an in-memory database that does not persist after process exit.
fix
Provide a file path for persistent storage, or use ':memory:' intentionally for test/transient data.
affects: all
Errors
Common errors & fixes
Cannot find module 'applesauce-sqlite' or its corresponding type declarations.
Importing from the root package instead of a driver subpath.
fix
Use import from 'applesauce-sqlite/better-sqlite3' (or libsql/native).
ERR_REQUIRE_ESM: require() of ES Module not supported.
Using CommonJS require() on an ESM-only package.
fix
Use dynamic import() or convert your project to ESM.
Error: The module '<path>/node_modules/better-sqlite3/build/Release/better_sqlite3.node' was compiled against a different Node.js version
better-sqlite3 native binary mismatch with Node.js version.
fix
Reinstall/rebuild better-sqlite3: npm rebuild better-sqlite3.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
@libsql/clientoptionalOptional: for libsql client backend
@tursodatabase/databaseoptionalOptional: for Turso database backend
@tursodatabase/database-wasmoptionalOptional: for Turso WASM backend
better-sqlite3optionalOptional: for better-sqlite3 backend
Agent activity
30 hits · last 30 days
node
26
OpenAI (training)
1
Resources
applesauce-sqlite — npm install applesauce-sqlite · libregistry