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

@terraza/db

v0.2.0

Published

Shared database client, schema, and user resolution for Terraza apps

Readme

@terraza/db

Shared database client, schema, and user resolution for Terraza apps. Centralizes the Neon serverless Pool setup, the Node.js 20 WebSocket workaround, the terraza.users Drizzle schema, and the user resolution query that every app needs.

Install

pnpm add @terraza/db

Usage

Database client

import { createDb, getDb } from "@terraza/db";

// Explicit connection string
const db = createDb(process.env.DATABASE_URL!);

// Or use the lazy singleton (reads DATABASE_URL from env)
const db = getDb();

Pool for custom schemas (schema merging)

If your app needs relational queries across both terraza.users and app-specific tables, use createPool to get a WebSocket-ready Neon Pool, then pass your merged schema to drizzle():

import { createPool } from "@terraza/db";
import { terrazaUsers } from "@terraza/db/schema";
import { drizzle } from "drizzle-orm/neon-serverless";
import * as appSchema from "./schema/index.js";

const pool = createPool(process.env.DATABASE_URL!);
const db = drizzle({ client: pool, schema: { terrazaUsers, ...appSchema } });

User resolution

import { resolveUser } from "@terraza/db";

const user = await resolveUser(db, "ken");
// → { id: "uuid", slug: "ken", displayName: "Ken Grafals" }

Throws if the slug doesn't exist in terraza.users.

Schema

The terraza.users table definition is available as a Drizzle schema for use in queries and joins:

import { terrazaUsers, terrazaSchema } from "@terraza/db/schema";

Exclude this from app-level migrations with schemaFilter in your drizzle.config.ts:

export default defineConfig({
  schemaFilter: ["your_app_schema"], // omit "terraza"
});

Exports

@terraza/db

| Export | Purpose | |--------|---------| | createDb(url) | Create a Drizzle client from a Neon connection string | | createPool(url) | Create a Neon Pool with WebSocket workaround (for schema merging) | | getDb() | Lazy singleton that reads DATABASE_URL from env | | resetDb() | Clear the singleton (for tests) | | resolveUser(db, slug) | Query terraza.users by slug, throw if not found | | terrazaSchema | Drizzle pgSchema("terraza") | | terrazaUsers | Drizzle table definition for terraza.users | | DbClient | Type alias for the Drizzle client | | Pool | Type alias for the Neon serverless Pool | | ResolvedUser | Type: { id, slug, displayName } | | User | Inferred select type for terraza.users | | NewUser | Inferred insert type for terraza.users |

@terraza/db/schema

Re-exports terrazaSchema, terrazaUsers, User, and NewUser for use in Drizzle configs and queries without pulling in the full package.

WebSocket workaround

Node.js 20 lacks a global WebSocket. This package detects that and configures @neondatabase/serverless to use the ws package automatically. When the VPS upgrades to Node 22+, this becomes a no-op — no changes needed in consuming apps.

Environment variables

| Variable | Purpose | |----------|---------| | DATABASE_URL | Neon connection string (used by getDb()) |

Development

npm run build   # TypeScript compilation to dist/
npm test        # Run vitest suite (9 tests)