Skip to content

nullableIdColumn

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

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

Drizzle custom column type for a nullable Id<Brand> column.

Behaves identically to idColumn except that null and undefined driver values are passed through as null rather than throwing. Use for optional foreign keys, LEFT JOIN results, and any column that is legitimately absent.

There is no generatedNullableIdColumn. A column that auto-generates its own ID should never be null at write time — that is the entire purpose of the generated variant. A nullable column is one that the caller explicitly sets to null; it cannot simultaneously be auto-generated. Use nullableIdColumn for optional foreign keys and generatedIdColumn for primary keys that must always be present. The same reasoning applies to the MySQL and SQLite equivalents (nullableIdColumnMysql, nullableIdColumnSqlite).

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> | null; dataType: "custom"; driverParam: string | null; enumValues: undefined; name: ""; }>

import { nullableIdColumn } from "@smonn/ids/drizzle";
import { createTimestampId } from "@smonn/ids";
const usr = createTimestampId("usr");
// default: text column
export const posts = pgTable("posts", {
authorId: nullableIdColumn(usr),
});
// posts.authorId is Id<"usr"> | null end-to-end
// explicit char column
export const comments = pgTable("comments", {
authorId: nullableIdColumn(usr, { columnType: "char(26)" }),
});