Skip to content

idColumn

idColumn<Brand>(codec, options?): PgCustomColumnBuilder<{ columnType: "PgCustomColumn"; data: Id<Brand>; dataType: "custom"; driverParam: string; enumValues: undefined; name: ""; }>

Defined in: src/adapters/drizzle.ts:105

Drizzle custom column type that stores an Id<Brand> as a canonical SQL string value in PostgreSQL.

Write path: validates the value via codec.safeParse and throws IdsError("invalid_id") if validation fails.

Read path: normalises the raw DB string via codec.safeParse(), not strict is(). Data at rest should already be canonical per ADR-0003, but safeParse is a safe boundary in case stale non-canonical values exist. Throws if the value from the database does not parse as a valid Id<Brand>.

Brand extends string

IdColumnCodec<Brand>

The brand-scoped codec used to parse values read from the database.

Optional column configuration.

string

SQL column type to use (default: "text"). Pass "varchar(30)" or "char(26)" to match an existing DDL or index strategy. The value is passed through verbatim — no validation is performed.

PgCustomColumnBuilder<{ columnType: "PgCustomColumn"; data: Id<Brand>; dataType: "custom"; driverParam: string; enumValues: undefined; name: ""; }>

import { idColumn } from "@smonn/ids/drizzle";
import { createTimestampId } from "@smonn/ids";
const usr = createTimestampId("usr");
// default: text column
export const users = pgTable("users", { id: idColumn(usr).primaryKey() });
// explicit varchar column
export const orgs = pgTable("orgs", { id: idColumn(usr, { columnType: "varchar(30)" }).primaryKey() });