Kadak

Schema

Define PostgreSQL tables in TypeScript without repeating yourself.

Schema

You want schema code that stays readable after month six.

KadakORM solves this with shorthand columns and optional builder methods.

Smallest useful schema

import { table } from '@shyk/kadak-orm'

export const users = table('users', {
  id: 'id',
  email: 'email',
  name: 'text',
  age: 'int?',
})

Why this is simpler

Before (manual naming everywhere):

// first_name in SQL, firstName in TS, repeated in both places

KadakORM:

firstName: 'text' // KadakORM maps to first_name automatically

Builder mode when you need control

import { z } from 'zod'
import { table, kadak } from '@shyk/kadak-orm'

export const users = table('users', {
  id: kadak.id(),
  email: kadak.email().unique(),
  name: kadak.text().min(2).max(120),
  profile: kadak.json(z.object({ theme: z.enum(['light', 'dark']) })),
  updatedAt: kadak.timestamp().default('now').autoUpdate(),
})

Table-level options

const users = table('users', {
  id: 'id',
  email: 'email',
}, {
  timestamps: true,
  softDelete: true,
  unique: [['email']],
})

Important: softDelete: true changes delete() behavior to soft delete.

Types from schema

import { type Infer, type InferInsert, type InferUpdate } from '@shyk/kadak-orm'

type User = Infer<typeof users>
type NewUser = InferInsert<typeof users>
type UserPatch = InferUpdate<typeof users>

On this page