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).
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> | null; dataType: "custom"; driverParam: string | null; enumValues: undefined; name: ""; }>
Example
Section titled “Example”import { nullableIdColumn } from "@smonn/ids/drizzle";import { createTimestampId } from "@smonn/ids";
const usr = createTimestampId("usr");// default: text columnexport const posts = pgTable("posts", { authorId: nullableIdColumn(usr),});// posts.authorId is Id<"usr"> | null end-to-end
// explicit char columnexport const comments = pgTable("comments", { authorId: nullableIdColumn(usr, { columnType: "char(26)" }),});