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

linkgress-orm

v0.4.10

Published

A lightweight, type-safe ORM for PostgreSQL with LINQ-style queries and automatic type inference

Readme

Linkgress ORM

npm version License: MIT TypeScript PostgreSQL

A type-safe ORM for PostgreSQL and TypeScript with automatic type inference and powerful query capabilities.

LINQ-Inspired Query Syntax: The query API is designed to feel familiar to developers coming from C# LINQ, with chainable methods like select(), where(), orderBy(), and groupBy(). You also get magic SQL string interpolation for when you need raw SQL power without sacrificing type safety.

PostgreSQL-First Philosophy: While other ORMs aim high and try to support all platforms, Linkgress is built exclusively for PostgreSQL. This allows it to leverage PostgreSQL's advanced features to the maximum—particularly in how collections and aggregations are retrieved using CTEs, LATERAL joins, JSON aggregations, and native PostgreSQL optimizations.

Features

  • Entity-First Approach - Define entities with DbColumn<T>, no decorators needed
  • Fluent Configuration API - Intuitive DbContext pattern with method chaining
  • Automatic Type Inference - Full TypeScript support without manual type annotations
  • Nested Collection Queries - Query one-to-many relationships with CTE, LATERAL, or temp table strategies
  • Type-Safe Aggregations - count(), sum(), max(), min() return proper types
  • Powerful Filtering - Type-checked query conditions
  • Prepared Statements - Build queries once, execute many times with named placeholders
  • Fluent Update/Delete - Chain .where().update() and .where().delete() with RETURNING support
  • Transaction Support - Safe, type-checked transactions
  • Manual Migrations - File-based migrations with journal tracking, up/down support, and scaffolding
  • Multiple Clients - Works with both pg and postgres npm packages

Table of Contents

Quick Start

Installation

npm install linkgress-orm postgres

See Installation Guide for detailed setup.

Define Entities

import { DbEntity, DbColumn } from 'linkgress-orm';

export class User extends DbEntity {
  id!: DbColumn<number>;
  username!: DbColumn<string>;
  email!: DbColumn<string>;
  posts?: Post[];  // Navigation property
}

export class Post extends DbEntity {
  id!: DbColumn<number>;
  title!: DbColumn<string>;
  userId!: DbColumn<number>;
  views!: DbColumn<number>;
  user?: User;  // Navigation property
}

Create DbContext

import { DbContext, DbEntityTable, DbModelConfig, integer, varchar } from 'linkgress-orm';

export class AppDatabase extends DbContext {
  get users(): DbEntityTable<User> {
    return this.table(User);
  }

  get posts(): DbEntityTable<Post> {
    return this.table(Post);
  }

  protected override setupModel(model: DbModelConfig): void {
    model.entity(User, entity => {
      entity.toTable('users');
      entity.property(e => e.id).hasType(integer('id').primaryKey().generatedAlwaysAsIdentity({ name: 'users_id_seq' }));
      entity.property(e => e.username).hasType(varchar('username', 100)).isRequired();
      entity.property(e => e.email).hasType(varchar('email', 255)).isRequired();

      entity.hasMany(e => e.posts, () => Post)
        .withForeignKey(p => p.userId)
        .withPrincipalKey(u => u.id);
    });

    model.entity(Post, entity => {
      entity.toTable('posts');
      entity.property(e => e.id).hasType(integer('id').primaryKey().generatedAlwaysAsIdentity({ name: 'posts_id_seq' }));
      entity.property(e => e.title).hasType(varchar('title', 200)).isRequired();
      entity.property(e => e.userId).hasType(integer('user_id')).isRequired();
      entity.property(e => e.views).hasType(integer('views')).hasDefaultValue(0);

      entity.hasOne(e => e.user, () => User)
        .withForeignKey(p => p.userId)
        .withPrincipalKey(u => u.id);
    });
  }
}

Query with Type Safety

import { eq, gt } from 'linkgress-orm';
import { PostgresClient } from 'linkgress-orm';

// Create a database client with connection pooling
const client = new PostgresClient('postgres://user:pass@localhost/db');

// Create a DbContext instance - reuse this across your application!
const db = new AppDatabase(client);

// Create schema
await db.ensureCreated();

// Insert
await db.users.insert({ username: 'alice', email: '[email protected]' });

// Query with filters
const activeUsers = await db.users
  .where(u => eq(u.username, 'alice'))
  .toList();

// Nested collection query with aggregations
const usersWithStats = await db.users
  .select(u => ({
    username: u.username,
    postCount: u.posts.count(),  // Automatic type inference - no casting!
    maxViews: u.posts.max(p => p.views),  // Returns number | null
    posts: u.posts
      .select(p => ({ title: p.title, views: p.views }))
      .where(p => gt(p.views, 10))
      .toList('posts'),
  }))
  .toList();

// Fluent update with RETURNING
const updatedUsers = await db.users
  .where(u => eq(u.username, 'alice'))
  .update({ email: '[email protected]' })
  .returning(u => ({ id: u.id, email: u.email }));

// Fluent delete
await db.users
  .where(u => eq(u.username, 'old_user'))
  .delete();

// Note: Only call dispose() when shutting down your application
// For long-running apps (servers), keep the db instance alive
// and dispose on process exit (see Connection Lifecycle docs)

Result is fully typed:

Array<{
  username: string;
  postCount: number;
  maxViews: number | null;
  posts: Array<{ title: string; views: number }>;
}>

Documentation

Getting Started

Guides

Advanced

Requirements

  • Node.js 16+
  • TypeScript 5.0+
  • PostgreSQL 12+

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support


Crafted with ❤️ for developers who love type safety and clean APIs.