npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

applesauce-sqlite

v5.2.0

Published

sqlite event databases for applesauce

Readme

applesauce-sqlite

A SQLite3 event database implementation for Applesauce, providing persistent storage for Nostr events. This package extends the core applesauce-core functionality by replacing the default in-memory event database with a persistent SQLite database.

Key Features

  • Persistent Storage: Store Nostr events in a SQLite database that persists between application restarts
  • Hybrid Architecture: Combines in-memory caching with SQLite persistence for optimal performance
  • Full Compatibility: Drop-in replacement for the default in-memory event database
  • Efficient Querying: Optimized SQLite queries for filtering and retrieving Nostr events
  • Built-in Relay: Includes a complete Nostr relay implementation using the SQLite database

Installation

# For better-sqlite3
npm install applesauce-sqlite better-sqlite3

# For libsql
npm install applesauce-sqlite @libsql/client

# For bun / deno / native sqlite
bun add applesauce-sqlite

Basic Usage

Using an event database with EventStore

import { EventStore } from "applesauce-core";
import { BetterSqlite3EventDatabase } from "applesauce-sqlite/better-sqlite3";

// Create a SQLite database (file-based or in-memory)
const database = new BetterSqlite3EventDatabase("./events.db"); // or ":memory:" for in-memory

// Create EventStore with SQLite backend
const eventStore = new EventStore(database);

// Use the event store as normal
eventStore.add(someNostrEvent);

// The events are now persisted to SQLite!

With Models and Subscriptions

import { EventStore } from "applesauce-core";
import { ProfileModel, TimelineModel } from "applesauce-core/models";
import { BetterSqlite3EventDatabase } from "applesauce-better-sqlite3";
import { Relay } from "nostr-tools/relay";

// Create persistent event store
const database = new BetterSqlite3EventDatabase("./events.db");
const eventStore = new EventStore(database);

// Connect to a relay and store events
const relay = await Relay.connect("wss://relay.example.com");
const sub = relay.subscribe([{ kinds: [0, 1] }], {
  onevent(event) {
    eventStore.add(event); // Events are automatically persisted
  },
});

// Use models as normal - they'll work with persisted data
const profile = eventStore.model(ProfileModel, "pubkey...");
profile.subscribe((parsed) => {
  console.log("Profile loaded from database:", parsed);
});

// Timeline will include events from previous sessions
const timeline = eventStore.model(TimelineModel, { kinds: [1] });
timeline.subscribe((events) => {
  console.log("Timeline with persisted events:", events.length);
});

Advanced Usage

Custom Relay Implementation

import { EventStore } from "applesauce-core";
import { BetterSqlite3EventDatabase } from "applesauce-better-sqlite3";
import { WebSocketServer } from "ws";

// Create your own relay with custom logic
const database = new BetterSqlite3EventDatabase("./custom-relay.db");
const eventStore = new EventStore(database);

const wss = new WebSocketServer({ port: 8080 });

wss.on("connection", (ws) => {
  ws.on("message", (data) => {
    const message = JSON.parse(data.toString());

    if (message[0] === "EVENT") {
      const event = message[1];
      const added = eventStore.add(event);

      if (added) {
        ws.send(JSON.stringify(["OK", event.id, true, ""]));
        // Broadcast to other clients...
      } else {
        ws.send(JSON.stringify(["OK", event.id, false, "rejected"]));
      }
    }
  });
});

License

MIT