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

@veap/database

v0.1.6

Published

Eloquent-like Active Record ORM powered by Knex with AsyncLocalStorage transactions

Readme

CI Release Version

@veap/database

Eloquent-inspired Active Record ORM powered by Knex with AsyncLocalStorage transaction scoping and automatic migrations for PostgreSQL, MySQL, and SQLite.

Overview

@veap/database brings expressive, developer-friendly Active Record modeling to TypeScript. It combines the ergonomic query building of Laravel Eloquent with the battle-tested reliability of Knex. With built-in AsyncLocalStorage context propagation, database transactions flow seamlessly across function and module boundaries without manual transaction object passing.

Features

  • Active Record models: Clean declarative models with timestamps, UUID primary keys, attribute casting (JSON, dates, booleans), and local scopes.
  • AsyncLocalStorage transactions: Zero-boilerplate transaction() blocks that bind nested queries automatically to the current transaction.
  • Expressive relations: Full relation graph support including belongsTo, hasMany, hasOne, belongsToMany, and polymorphic variants (morphTo, morphMany, morphOne, morphToMany).
  • Eager loading & query builder: Fluid chainable queries with .with(), .where(), .orderBy(), .paginate(), and .first().
  • Knex proxy & raw queries: Direct access to Knex via getKnex() and the convenient dynamic proxy dbClient.
  • Migration & Schema runner: Declarative Schema builder and automated migration runner supporting versioned schema updates.
  • IoC integration: Ships with DatabaseServiceProvider and MigrationServiceProvider for modular Veap applications.

Installation

# Using bun
bun add @veap/database better-sqlite3 # or pg / mysql2

# Using pnpm
pnpm add @veap/database better-sqlite3

# Using npm
npm install @veap/database better-sqlite3

Usage

Define Active Record Models

Create models extending the base Model class:

import { Model, belongsTo, hasMany } from "@veap/database";
import type { BelongsTo, HasMany } from "@veap/database";

export class Author extends Model {
  static override tableName = "authors";

  declare id: string;
  declare name: string;
  declare email: string;

  public posts(): HasMany<Post> {
    return hasMany(this, Post, "author_id");
  }
}

export class Post extends Model {
  static override tableName = "posts";

  declare id: string;
  declare title: string;
  declare content: string;
  declare author_id: string;

  public author(): BelongsTo<Author> {
    return belongsTo(this, Author, "author_id");
  }
}

Querying and CRUD Operations

Perform common queries and persistence operations:

// Create
const author = await Author.create({
  name: "Ada Lovelace",
  email: "[email protected]",
});

// Find and update
const post = await Post.query().where("slug", "first-post").first();
if (post) {
  post.title = "Updated Title";
  await post.save();
}

// Eager loading relations
const postsWithAuthors = await Post.query()
  .with("author")
  .where("status", "published")
  .orderBy("created_at", "desc")
  .get();

Seamless Transactions with AsyncLocalStorage

Run operations inside a transaction without passing around connection objects:

import { transaction } from "@veap/database";

await transaction(async () => {
  const author = await Author.create({
    name: "Grace Hopper",
    email: "[email protected]",
  });

  await Post.create({
    title: "Compilers and Nanoseconds",
    content: "...",
    author_id: author.id,
  });
  // If any error is thrown, the entire block rolls back automatically.
});

Standalone Database Initialization

When using outside the Veap application builder:

import { initDatabase } from "@veap/database";

initDatabase({
  client: "better-sqlite3",
  connection: {
    filename: "./data/app.sqlite",
  },
  useNullAsDefault: true,
});

IoC Service Provider Setup

When composing inside a Veap application:

import { Application } from "@veap/kernel";
import { DatabaseServiceProvider } from "@veap/database";

export const app = Application.configure()
  .use(DatabaseServiceProvider)
  .create();

Subpath Exports

| Export Path | Content | | ---------------- | ----------------------------------------------------------------------- | | @veap/database | Core ORM, Model, relations, transactions, schema builder, and providers |

Documentation

For full guides and relational modeling patterns, visit:

License

MIT