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

terradb

v0.5.6

Published

Declarative schema management for PostgreSQL and SQLite

Readme

terradb

Declarative schema management for PostgreSQL and SQLite.

Install

npm install -g terradb

Quick Start

PostgreSQL

-- schema.sql
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) NOT NULL UNIQUE
);
export DATABASE_URL="postgres://user:password@localhost:5432/mydb"
terradb plan   # preview changes
terradb apply  # apply changes

SQLite

-- schema.sql
CREATE TABLE users (
  id INTEGER PRIMARY KEY,
  email TEXT NOT NULL UNIQUE
);
export DATABASE_URL="sqlite:///path/to/database.db"
terradb plan
terradb apply

How It Works

  1. Write your desired schema as CREATE statements
  2. Run terradb plan to see what changes are needed
  3. Run terradb apply to execute the changes

terradb compares your schema file against the current database state and generates the necessary ALTER/DROP/CREATE statements.

Configuration

PostgreSQL

export DATABASE_URL="postgres://user:password@localhost:5432/mydb"

Or individual variables:

export DB_HOST=localhost
export DB_PORT=5432
export DB_NAME=mydb
export DB_USER=postgres
export DB_PASSWORD=password

SQLite

export DATABASE_URL="sqlite:///path/to/database.db"
# or
export DATABASE_URL="/path/to/database.db"
# or in-memory
export DATABASE_URL=":memory:"

Feature Support

| Feature | PostgreSQL | SQLite | |---------|------------|--------| | Tables & Columns | Yes | Yes | | Primary Keys | Yes | Yes | | Foreign Keys | Yes | Yes | | Indexes | Yes | Yes | | Unique Constraints | Yes | Yes | | Check Constraints | Yes | Yes | | Views | Yes | Yes | | ENUM Types | Yes | No | | Sequences | Yes | No | | Functions | Yes | No | | Procedures | Yes | No | | Triggers | Yes | No | | Materialized Views | Yes | No | | Schemas | Yes | No | | Extensions | Yes | No |

SQLite uses table recreation for schema changes that ALTER TABLE doesn't support (column type changes, constraint modifications, etc.).

Commands

terradb plan                    # Preview changes
terradb plan -f custom.sql      # Use custom schema file
terradb apply                   # Apply changes
terradb apply -f custom.sql     # Apply from custom file

Examples

Constraints

-- Primary keys
id SERIAL PRIMARY KEY           -- PostgreSQL
id INTEGER PRIMARY KEY          -- SQLite

-- Foreign keys
CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE

-- Check constraints
CONSTRAINT check_positive CHECK (quantity > 0)

-- Unique constraints
CONSTRAINT unique_email UNIQUE (email)

Indexes

CREATE INDEX idx_email ON users (email);
CREATE INDEX idx_active ON users (email) WHERE active = true;  -- partial index
CREATE UNIQUE INDEX idx_unique_email ON users (email);

PostgreSQL-only Features

-- ENUM types
CREATE TYPE status AS ENUM ('pending', 'active', 'inactive');

-- Views
CREATE VIEW active_users AS SELECT * FROM users WHERE active = true;
CREATE MATERIALIZED VIEW user_stats AS SELECT COUNT(*) FROM users;

-- Functions
CREATE FUNCTION add(a INT, b INT) RETURNS INT AS $$ SELECT a + b $$ LANGUAGE SQL;

-- Sequences
CREATE SEQUENCE custom_seq START 1000 INCREMENT 1;

Development

Requires Bun:

git clone https://github.com/elitan/terradb.git
cd terradb
bun install

# PostgreSQL tests
docker compose up -d
bun test

# SQLite tests (no docker needed)
bun test src/test/sqlite/

License

MIT