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

@bjnstnkvc/db

v21.0.1

Published

TypeScript database layer for IndexedDB with an API modeled on Laravel.

Readme

DB

A database layer for IndexedDB, with an API modeled on Laravel's: a DB class, a fluent query builder, a schema builder and forward-only migrations that run when your app boots.

The method names and their semantics follow Laravel closely enough that the docs are worth reading side by side, and the documentation links each Laravel page it draws from. It is not a port: IndexedDB is a key-value store with no query language, so the places where behavior has to differ are called out where they arise. This project is not affiliated with the Laravel project.

Contents

Installation

You can install the package via npm:

npm install @bjnstnkvc/db

and then import it into your project

import { DB, Schema, Migration, type Blueprint } from '@bjnstnkvc/db';

The package supports Chrome 93, Edge 93, Firefox 92 and Safari 15.4 or later.

Quick start

Declare your connections once, at module scope, then migrate when the app boots:

import { DB, Schema, Migration, type Blueprint, type Transaction } from '@bjnstnkvc/db';

interface User {
    id: number;
    name: string;
    email: string;
    age: number | null;
    role: string;
    created_at: Date | null;
    updated_at: Date | null;
}

class CreateUsersTable extends Migration {
    /**
     * Run the migration.
     */
    override async up(): Promise<void> {
        await Schema.create('users', (table: Blueprint): void => {
            table.id();
            table.string('name');
            table.string('email').unique();
            table.integer('age').nullable().index();
            table.string('role').default('member').index();
            table.timestamps();
        });
    }
}

DB.configure({
    default    : 'app',
    connections: {
        app: {
            database  : 'app',
            migrations: [CreateUsersTable],
        },
    },
});

await DB.migrate('app');

DB.migrate(name) is idempotent, so calling it on every boot is the intended usage. Then query:

await DB.table<User>('users').insert({ name: 'John', email: '[email protected]', age: 30 });

const users: User[] = await DB.table<User>('users')
    .where('age', '>=', 18)
    .whereIn('role', ['admin', 'owner'])
    .orderBy('created_at', 'desc')
    .limit(10)
    .get();

await DB.transaction(async (transaction: Transaction): Promise<void> => {
    const id: IDBValidKey = await transaction.table<User>('users').insertGetId({ name: 'Jane', email: '[email protected]' });

    await transaction.table('posts').insert({ user_id: id, title: 'Hello' });
});

Documentation

  • Configuration: declaring connections, migrating at boot, and resolving, disconnecting and purging connections
  • Migrations: forward-only migrations, what a migration may await, and migration status
  • Seeding: seeders, which connection they write to, running them safely on every boot, and rebuilding from scratch
  • Defining a schema: column types and modifiers, altering and changing columns, indexes over renamed and dropped columns, dropping or renaming a column the same callback declares, decimals, enums, coercing rows already stored, and reserved tables
  • Querying: constraints, JSON columns, shaping, terminals and writes
  • Joins: inner, left, right and cross joins, and what they cost
  • Grouping: groupBy, typed aggregates and having
  • Query plans: how constraints become an index range, and explain()
  • Transactions: transaction scope, nesting and what the callback may await
  • Events: listening for query, transaction, migration and seeding events, and the query log
  • Multiple tabs: blocked upgrades and databases changed by another tab
  • Storage quota: quota errors, usage estimates and asking not to be evicted
  • Exceptions: every exception the package throws, and when

Where it differs from Laravel

  • Migrations only run forward. IndexedDB versions cannot decrease, so there is no down() and no rollback(), and migrations may only be appended. DB.fresh(name) starts over. See Migrations.
  • A migration or transaction may only await this package. IndexedDB commits a transaction the moment its queue drains, so awaiting a fetch or a timer ends it early, and the next call throws MigrationTransactionClosedException or TransactionClosedException. Network data belongs in a seeder. See What a migration may await and What the callback may await.
  • Schema changes only run inside a migration, since they need the version-change transaction. The read side works anywhere. See Schema outside a migration.
  • Column types are enforced by this package at write time, because IndexedDB stores whole objects and checks nothing itself. See Defining a schema.
  • There is no beginTransaction(), commit() or rollBack(), and a transaction made while another runs on the connection joins it, since IndexedDB has no savepoints. See Transactions.
  • Joins and grouping run in memory, writes through a join reach the base table only, and aggregates are named in a typed object rather than raw SQL. See Joins and Grouping.
  • A query uses at most one index. explain() shows which. See Query plans.
  • The browser adds its own failure modes: storage quota, eviction and other tabs holding the database open. See Storage quota and Multiple tabs.

Testing

IndexedDB does not exist in Node, so point your test setup at fake-indexeddb:

In tests/setup.ts:

import 'fake-indexeddb/auto';

And in vitest.config.ts:

export default defineConfig({
    test: {
        setupFiles: ['./tests/setup.ts'],
    },
});

Give each test file its own database name so the suites do not share state.