Skip to content

PostgreSQL-optimized TypeScript ORM

Built exclusively for Postgres. Type-safe fluent query builder, decorator-based models, and queries tuned for Postgres performance.

What it looks like

Define a model, query it — that's it.

ts
import { column, primaryColumn, table, Entity, initialize } from 'bigal';
import { Pool } from 'postgres-pool';

@table({ name: 'products' })
class Product extends Entity {
  @primaryColumn({ type: 'integer' })
  public id!: number;

  @column({ type: 'string', required: true })
  public name!: string;

  @column({ type: 'integer', required: true })
  public priceCents!: number;

  @column({ model: () => 'Store', name: 'store_id' })
  public store!: number | Store;
}

const repos = initialize({
  models: [Product, Store],
  pool: new Pool('postgres://localhost/mydb'),
});
const productRepo = repos.Product as Repository<Product>;

// Fluent queries — just await the chain
const products = await productRepo
  .find()
  .where({ priceCents: { '>': 1000 }, name: { contains: 'widget' } })
  .sort('name asc')
  .limit(10);

// Joins and subqueries
const expensiveProducts = await productRepo
  .find()
  .join('store')
  .where({
    store: { name: 'Acme' },
    price: { '>': subquery(productRepo).avg('price') },
  });

// Upserts with ON CONFLICT
await productRepo.create({ name: 'Widget', sku: 'WDG-001', priceCents: 999 }, { onConflict: { action: 'merge', targets: ['sku'], merge: ['priceCents'] } });