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

@anabranch/db

v0.3.1

Published

Database abstraction with Task/Stream semantics. In-memory adapter for testing, adapters for PostgreSQL, MySQL, and SQLite.

Readme

@anabranch/db

Type-safe database abstraction with query building, transactions, and streaming support.

Provides a unified API across PostgreSQL, MySQL, and SQLite through adapter packages.

Usage

import { DB } from '@anabranch/db'
import { createPostgres } from '@anabranch/db-postgres'

const db = new DB(
  await createPostgres({ connectionString: 'postgresql://...' }).connect(),
)

// Query with type inference
const users = await db
  .query<{ id: number; name: string }>('SELECT * FROM users')
  .run()

// Transactions with automatic rollback on error
await DB.withConnection(
  createPostgres({}),
  (db) =>
    db.withTransaction(async (tx) => {
      await tx.execute("INSERT INTO users (name) VALUES ('Alice')")
    }),
).run()

// Stream large result sets
for await (const row of db.stream('SELECT * FROM large_table')) {
  if (row.type === 'success') {
    console.log(row.value)
  }
}

Adapters

API

DB(adapter)

Creates a DB instance from a connected adapter.

import { DB } from '@anabranch/db'

const db = new DB(adapter)

query(sql, params?)

Executes a SELECT query and returns results.

const users = await db
  .query<{ id: number; name: string }>('SELECT * FROM users WHERE active = ?', [
    true,
  ])
  .run()

execute(sql, params?)

Executes INSERT, UPDATE, DELETE or DDL statements.

const result = await db
  .execute('INSERT INTO users (name) VALUES (?)', ['Alice'])
  .run()
console.log(result.affectedRows)

stream(sql, params?)

Streams rows from a query result.

for await (const row of db.stream('SELECT * FROM users')) {
  if (row.type === 'success') {
    console.log(row.value)
  }
}

withTransaction(fn)

Executes a callback within a transaction, automatically committing on success or rolling back on error.

await db.withTransaction(async (tx) => {
  await tx.execute('INSERT INTO accounts (balance) VALUES (100)')
  await tx.execute('INSERT INTO accounts (balance) VALUES (-100)')
}).run()

DB.withConnection(connector, fn)

Acquires a connection, runs a callback, and releases the connection. Supports transactions.

const result = await DB.withConnection(
  createPostgres({}),
  (db) =>
    db.withTransaction(async (tx) => {
      await tx.execute('INSERT INTO orders DEFAULT VALUES')
      return tx.query('SELECT LAST_INSERT_ID()')
    }),
).run()