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>.
Type Parameters
Section titled “Type Parameters”Brand extends string
Parameters
Section titled “Parameters”IdColumnCodec<Brand>
The brand-scoped codec used to parse values read from the database.
options?
Section titled “options?”Optional column configuration.
columnType?
Section titled “columnType?”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.
Returns
Section titled “Returns”PgCustomColumnBuilder<{ columnType: "PgCustomColumn"; data: Id<Brand>; dataType: "custom"; driverParam: string; enumValues: undefined; name: ""; }>
Example
Section titled “Example”import { idColumn } from "@smonn/ids/drizzle";import { createTimestampId } from "@smonn/ids";
const usr = createTimestampId("usr");// default: text columnexport const users = pgTable("users", { id: idColumn(usr).primaryKey() });// explicit varchar columnexport const orgs = pgTable("orgs", { id: idColumn(usr, { columnType: "varchar(30)" }).primaryKey() });