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

@zerotal/orm

v1.7.5

Published

Active Record ORM for Zerotal built on Bun.sql — models, relations, query builder, migrations, and schema.

Readme

@zerotal/orm

Active Record ORM for Bun — models, migrations, and a fluent query builder on top of Bun.sql.

@zerotal/orm maps TypeScript classes to database tables: declare columns with decorators, define relationships, and read/write data through a chainable query builder. It supports SQLite, PostgreSQL, and MySQL with the same model code, plus migrations, soft deletes, eager loading, and pagination.

Part of the Zerotal framework. Requires Bun ≥ 1.3.14.

Installation

bun add @zerotal/orm

Setup

Register the provider in bootstrap/providers.ts:

import { DatabaseProvider } from "@zerotal/orm";

export default [
  // …your other providers
  DatabaseProvider,
];

Configure a connection in config/database.ts:

import { DatabaseConfig } from "@zerotal/orm";
import { env } from "@zerotal/core";

export default DatabaseConfig({
  driver: env("DB_DRIVER", "sqlite"), // 'sqlite' | 'postgres' | 'mysql'
  url: env("DATABASE_URL", "./database/db.sqlite"),
  replicas: [], // optional read-replica URLs
});

Usage

Define a model

import { Model, column, table, belongsTo, hasMany } from "@zerotal/orm";
import type { Columns } from "@zerotal/orm";

@(table("posts").withTimestamps().withSoftDeletes())
export class Post extends Model {
  static fillable: Columns<Post>[] = ["title", "body", "status", "userId"];

  @column("string") title!: string;
  @column("text") body!: string;
  @column("string") status!: string;
  @column("integer") userId!: number;

  @belongsTo(() => User, { foreignKey: "userId" })
  author!: User;

  @hasMany(() => Comment, { foreignKey: "postId" })
  comments!: Comment[];
}

Query records

const post = await Post.find(1); // or findOrFail(1) to throw
const published = await Post.query()
  .where("status", "published")
  .orderBy("created_at", "desc")
  .get<Post>();

const created = await Post.create({ title: "Hello", body: "…", status: "draft" });

post.fill({ title: "Updated" });
await post.save();

await post.delete(); // soft delete (table has .withSoftDeletes())
await post.restore(); // un-delete
await post.forceDelete(); // permanent

Paginate

const page = await Post.query()
  .where("status", "published")
  .orderBy("created_at", "desc")
  .paginate(15, Number(http.query("page", "1")));

page.data; // Post[] for this page
page.total; // total matching rows
page.lastPage; // number of pages

Migrations

import { Migration, Schema } from "@zerotal/orm";

export default class CreatePostsTable extends Migration {
  async up(): Promise<void> {
    await Schema.create("posts", (table) => {
      table.increments("id");
      table.integer("user_id").index();
      table.string("title");
      table.text("body");
      table.softDeletes();
      table.timestamps();
    });
  }

  async down(): Promise<void> {
    await Schema.drop("posts");
  }
}

Run them with bun zt migrate (--fresh, migrate:rollback, migrate:status also available).

Raw query builder

import { DB } from "@zerotal/orm";

const rows = await DB.table("settings").where("key", "theme").first();
await DB.table("settings").upsert(
  { key: "theme", value: "dark" },
  { key: "theme" },
  { value: "dark" },
);

Exports

This package exposes two subpath entry points:

| Subpath | Contents | | ------------- | --------------------------------------------------------------------------------- | | . (default) | The full ORM runtime — see the table below. | | ./commands | CLI command classes used by the zerotal binary (make:model, migrate, etc.). |

Main exports from the default entry point:

  • ModelsModel (aka BaseModel), ModelQueryBuilder, DB, QueryBuilder
  • Decoratorscolumn, table, belongsTo, hasMany, hasOne, manyToMany, morphTo, morphMany, morphOne, hasManyThrough, hasOneThrough, morphToMany, morphedByMany
  • Schema / migrationsSchema, Blueprint, Migration, MigrationRunner, SchemaInspector, ModelInspector, SchemaDiffer, synchronizeSchema
  • SeedingSeeder
  • CastsCast, JsonCast, ArrayCast, json, objectOf, arrayOf
  • Hooks & observersHookRegistry, ModelObserver
  • N+1 detectionpreventNPlusOne, allowNPlusOne, NPlusOneError
  • ErrorsModelNotFoundError, RelationNotLoadedError, TransactionError, MigrationError, StateError
  • Provider & configDatabaseProvider, DatabaseConfig
  • TypesColumns, InsertPayload, UpdatePayload, PaginateResult, CursorPaginateResult, and more

Documentation