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

pledgedb

v0.1.0

Published

Embedded SQL database with vector search — WASM

Readme

PledgeDB WASM

Embedded SQL database with vector search, compiled to WebAssembly.

Building

# Install wasm-pack if you haven't
cargo install wasm-pack

# Build for browser
./build.sh

# Build for Node.js
./build.sh nodejs

# Build for bundlers (webpack, vite, etc.)
./build.sh bundler

The built package will be in pkg/.

Usage (Browser)

import { PledgeDB } from "pledgedb";

// Create in-memory database
const db = new PledgeDB();
db.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");
db.exec("INSERT INTO users (name) VALUES ('Alice')");

// Query
const result = db.query("SELECT * FROM users");
console.log(result.rows);   // [[1, "Alice"]]
console.log(result.columns); // ["id", "name"]

// Vector search
db.exec("CREATE TABLE items (id INTEGER PRIMARY KEY, embedding VECTOR(3))");
db.exec("INSERT INTO items (embedding) VALUES ([1.0, 0.0, 0.0])");
db.exec("INSERT INTO items (embedding) VALUES ([0.0, 1.0, 0.0])");
db.exec("CREATE VECTOR INDEX idx ON items (embedding) USING HNSW (metric = 'l2')");

const results = db.query("SELECT id FROM items ORDER BY embedding <-> [1.0, 0.0, 0.0] LIMIT 2");

// Persistence — automatic OPFS with IndexedDB fallback
await db.save("mydb");

// Later — load from storage
const db2 = new PledgeDB();
await db2.load("mydb");
const rows = db2.query("SELECT * FROM users");

// Manual persistence (for environments without OPFS/IndexedDB)
const bytes = db.export_data();
const db3 = PledgeDB.from_bytes(bytes);

Usage (Node.js)

const { PledgeDB } = require("pledgedb");

const db = new PledgeDB();
db.exec("CREATE TABLE data (id INTEGER PRIMARY KEY, value TEXT)");
db.exec("INSERT INTO data (value) VALUES ('hello')");

const result = db.query("SELECT * FROM data");
console.log(result);

Usage (Web Worker)

import { PledgeDB } from "pledgedb";

const db = new PledgeDB();
db.exec("CREATE TABLE cache (key TEXT PRIMARY KEY, value TEXT)");

// OPFS is available in Web Workers — save/load works the same
await db.save("cache-db");
await db.load("cache-db");

Persistence

PledgeDB WASM supports automatic persistence via:

  1. OPFS (Origin Private File System) — preferred, stores files at opfs:/pledgedb/<name>.pldb
  2. IndexedDB — fallback when OPFS is not available

Both are async APIs. Use save() and load() for automatic backend selection:

// Check what's available
console.log(PledgeDB.hasOpfs());       // true if OPFS is available
console.log(PledgeDB.hasIndexedDB());  // true if IndexedDB is available

// Save (automatically picks OPFS or IndexedDB)
await db.save("mydb");  // → "opfs" or "indexeddb"

// Load (automatically picks the same backend)
await db.load("mydb");  // → "opfs", "indexeddb", or "empty"

// Delete saved data
await PledgeDB.deleteSaved("mydb");

For environments without OPFS/IndexedDB (e.g. Cloudflare Workers), use manual persistence:

const bytes = db.export_data();
// Store bytes in KV, R2, or any storage
const db2 = PledgeDB.from_bytes(bytes);

API

new PledgeDB()

Create a new in-memory database.

PledgeDB.from_bytes(data: Uint8Array)

Load a database from previously exported bytes.

db.exec(sql: string): JsResult

Execute a SQL statement. Returns { columns, rows, affected, message }.

db.query(sql: string): JsResult

Alias for exec().

db.tables(): string[]

List all table names.

db.schema(name: string): JsSchema | null

Get the schema for a table.

db.export_data(): Uint8Array

Export raw database bytes for manual persistence.

db.flush(): void

Flush pending writes (no-op in WASM, kept for API compatibility).

db.save(name: string): Promise<string>

Persist to OPFS or IndexedDB. Resolves to "opfs" or "indexeddb".

db.load(name: string): Promise<string>

Load from OPFS or IndexedDB. Resolves to "opfs", "indexeddb", or "empty".

PledgeDB.hasOpfs(): boolean

Check if OPFS is available in the current environment.

PledgeDB.hasIndexedDB(): boolean

Check if IndexedDB is available in the current environment.

PledgeDB.deleteSaved(name: string): Promise<boolean>

Delete a saved database from OPFS and IndexedDB.