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

@sx3/database

v1.1.0

Published

A wrapper around the IndexedDB API.

Readme

npm

SX3 Database

This is a migration based wrapper around the IndexedDB API.

Installation

npm install @sx3/database

Usage

Readwrite

Read:

import { Database } from "@sx3/database";

const db = await new Database("mydb").open();

const users = await db.transaction("users").store().getAll();

Write:

const db = await new Database("mydb").open();

const userStore = db.transaction("users", "readwrite").store();

const id = await userStore.add({ name: "SX3", age: 99 });

Delete:

const db = await new Database("mydb").open();

const userStore = db.transaction("users", "readwrite").store();

await userStore.delete(1);

Multiple storages

const db = await new Database("mydb").open();
const trx = db.transaction(["users", "posts"], "readwrite");

const usersStore = trx.store("users");
const postsStore = trx.store("posts");

// Some actions ...

trx.commit(); // not necessarily

Native APIs are available

const db = new Database("mydb");
await db.open();

db.addEventListener("abort", () => {});
db.deleteObjectStore("users");
db.close();
// etc..

const trx = db.transaction("users");
trx.objectStore("users");
trx.addEventListener("complete", () => {});
// etc..

Delete database

new Database("mydb").delete();

Cursors

Iterate over the entire store

import { Database } from "@sx3/database";

const db = new Database("mydb");
await db.open();

const usersStore = db.transaction("users").store();
for await (const cursor of usersStore) {
  console.log(cursor.value);
}

Iterate over with query

const db = new Database("mydb");
await db.open();

const usersStore = db.transaction("users").store();
const range = IDBKeyRange.bound(20, 30);
for await (const cursor of usersStore.iterate(range)) {
  console.log(cursor.value);
}

Iterate over index.

Iterating over an index is similar to iterating over a store

const db = new Database("mydb");
await db.open();

const usersStore = db.transaction("users").store();
const index = usersStore.index("age");
for await (const cursor of index) {
  console.log(cursor.value);
}

Database migrations

DB migrations are an array of schemas:

import { MigrationSchema, Database } from "@sx3/database";

const postsSchema: MigrationSchema = {
  1: builder => builder.create("posts").index("id"),
};

const commentsSchema: MigrationSchema = {
  2: builder =>
    builder.create("comments").index("entity", ["entity_name", "entity_id"]),
};

// Version calculated from migrations
const db = new Database("mydb", { migrations: [postsSchema, commentsSchema] });

Async migrations

Async migrations allow lazy loading while opening a connection to the database:

import { MigrationSchema, Database } from "@sx3/database";

const asyncSchema = () =>
  new Promise<MigrationSchema>(resolve => {
    resolve({
      1: builder => builder.create("users").index("id"),
    });
  });

const db = await new Database("mydb", { migrations: [asyncSchema] }).open();

You can also load migrations from other files, for example your project structure might look like this:

modules
├─ moduleA
│  └─ store
│     ├─ posts.ts
│     └─ comments.ts
└─ moduleB
   └─ store
      ├─ cart.ts
      └─ wishlist.ts

This code imports migration schemas from all your module stores:

import { MigrationSchema, Database } from "@sx3/database";

const schemas = import.meta.glob<MigrationSchema>("./modules/**/store/*.ts", {
  import: "migrations",
});

const db = new Database("mydb", {
  migrations: Object.values(schemas),
});

Errors

Within this library, 3 new errors have been introduced:

  • NotOpenedError - Database is not open
  • BlockedError - Database is locked
  • NoStoreProvidedError - No store provided for transaction
import {
	Database,
	NotOpenedError,
	BlockedError,
	NoStoreProvidedError,
} from "@sx3/database";

const db = new Database("mydb");

try {
	await db.open();
} catch (error: unknown) {
	if (error instanceof BlockedError) {
		// Do something
	}
}