Skip to content

pgboType-safe PostgreSQL Business Objects

Tables, views, domains, auto-migration, native i18n — built on PostgreSQL, with zero codegen.

Quick start

bash
npm install @pgbo/core
typescript
import { createDatabase } from '@pgbo/core'
import { table, view, text, integer } from '@pgbo/core/schema'

const warehouse = table('warehouse', {
  columns: {
    slug: text().notNull(),
    name: text().notNull(),
    capacity: integer().min(0),
  },
  primaryKey: ['slug'],
})

const warehouseView = view('warehouse_view').from(warehouse)

const db = createDatabase({ connectionString: 'postgresql://localhost/mydb' })
const rows = await db.from(warehouseView).execute()

The three-layer model

┌─────────────────────────────────────────────────┐
│  Business Object (BO)                           │
│  Marks a view as a managed entity.              │
│  Owns CRUD lifecycle, permissions, hooks.       │
├─────────────────────────────────────────────────┤
│  View                                           │
│  PostgreSQL VIEW — the read/write interface.    │
│  Application code only talks to views.          │
├─────────────────────────────────────────────────┤
│  Table                                          │
│  PostgreSQL TABLE — pure data storage.          │
│  Never accessed directly by application code.   │
└─────────────────────────────────────────────────┘

Application code never touches tables directly. All reads and writes flow through views. Views become Business Objects when they need CRUD lifecycle, permissions, and hooks.

Next steps — read the Architecture overview, then dive into Schema Definition, Query Builder, or Business Objects.

Released under the MIT License.