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

dbuddy

v0.0.4

Published

postgres library

Readme

DBuddy

A TypeScript SQL library for PostgreSQL.

npm version npm downloads License: MIT

Installation

npm install dbuddy

# Or install the beta version
npm install dbuddy@beta

Development Setup

Prerequisites

  • Node.js 18+
  • Docker and Docker Compose

Installation

npm install

Environment Configuration

Copy the example environment file and configure your database settings:

cp .env.example .env

Edit .env with your database configuration:

# Standard PostgreSQL environment variables
PGHOST=localhost
PGPORT=15432
PGDATABASE=dbuddy_dev
PGUSER=postgres
PGPASSWORD=postgres

# Alternative: use DATABASE_URL
# DATABASE_URL=postgresql://postgres:postgres@localhost:15432/dbuddy_dev

Database Setup

Start the PostgreSQL database:

docker-compose up -d

The database will be available at localhost:15432 with:

  • Database: dbuddy_dev
  • User: postgres
  • Password: postgres

Development

# Build the library
npm run build

# Watch mode for development
npm run dev

# Run tests
npm test

# Run tests once
npm run test:run

# Run tests with coverage
npm run test:coverage

# Lint code
npm run lint

# Fix linting issues
npm run lint:fix

# Type check
npm run typecheck

TypeScript Type Generation

Generate TypeScript interfaces and query builders from your database schema:

# Generate types for all tables
npx dbuddy

# Generate types for all tables in a specific directory
npx dbuddy ./my-types

# Generate types for specific tables only
npx dbuddy ./generated users posts comments

# Via npm scripts (alternative)
npm run generate
npm run generate:types

This will create TypeScript files with:

  • Interface definitions for each table
  • Typed query builder classes
  • Factory functions for creating queries

Usage

import { Database, getDatabaseConfig } from 'dbuddy'

// Option 1: Use environment variables (reads from .env automatically)
const db = new Database()

// Option 2: Use explicit configuration
const db2 = new Database({
  host: 'localhost',
  port: 15432,
  database: 'dbuddy_dev',
  user: 'postgres',
  password: 'postgres'
})

// Option 3: Get config object from environment
const config = getDatabaseConfig()
const db3 = new Database(config)

// Execute query
const result = await db.query('SELECT * FROM users')
console.log(result.rows)

// Parameterized query
const user = await db.query('SELECT * FROM users WHERE id = $1', [1])

// Close connection
await db.close()

Using Generated Types

After generating types, you can use them for type-safe database queries:

import { Database } from 'dbuddy'
import { userQuery, User } from './generated'

const db = new Database()

// Type-safe queries with auto-completion
const users = await userQuery(db)
  .where(q => q.isActive.equals(true))
  .and(q => q.createdAt.greaterThan(new Date('2024-01-01')))
  .select()

// users is typed as User[]
console.log(users[0].firstName) // Type-safe property access

Database Migrations

DBuddy includes a comprehensive migration system for managing database schema changes:

# Initialize migration system
npx dbuddy migration init

# Create a new migration
npx dbuddy migration create add_users_table

# Apply pending migrations
npx dbuddy migration up

# Check migration status
npx dbuddy migration status

# Rollback migrations
npx dbuddy migration down

# Dry run (preview without executing)
npx dbuddy migration up --dry-run

See MIGRATION.md for complete migration documentation.

License

MIT