🪨
damian
Fundamentals

Custom typings

Override inferred types for specific columns

damian generate maps columns to built-in types: varchar becomes string, jsonb becomes any. Custom typings let you replace those with any Standard Schema-compatible validator.


Define overrides

Create ./damian/typings.ts and export a default object that satisfies Typings. Only include the columns you want to override.

./damian/typings.ts
import type { Typings } from './.generated/typings'
import { z } from 'zod'
import * as v from 'valibot'
import { type } from 'arktype'

export default {
    public: {
        users: {
            role: z.enum(["admin", "user"])
        },
        events: {
            metadata: v.object({ source: v.string() })
        },
        orders: {
            status: type("'pending' | 'shipped' | 'delivered'")
        }
    }
} satisfies Typings

Run generate

npx damian generate

Affected columns in tables.ts will use your validators, and queries on those tables automatically reflect the narrower types.


Extra: understand the generated file

damian generate produces ./damian/.generated/typings.ts:

./damian/.generated/typings.ts
import type { CreateTypings } from '@damiandb/pg'

export const typings = CreateTypings<{
  public: {
    users: {
      id: any
      name: any
      role: any
    }
    posts: {
      id: any
      payload: any
    }
  }
}>

CreateTypings validates structure and provides autocomplete for all schema, table, and column names.

On this page