Skip to content

generatedIdColumnMysql

generatedIdColumnMysql<Brand>(codec, options?): HasRuntimeDefault<HasDefault<MySqlCustomColumnBuilder<{ columnType: "MySqlCustomColumn"; data: Id<Brand>; dataType: "custom"; driverParam: string; enumValues: undefined; name: ""; }>>>

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

Drizzle custom column type that stores an Id<Brand> as a canonical text value in MySQL, with a client-side .$defaultFn so inserts that omit the field receive a freshly generated ID automatically.

Write path: .$defaultFn(() => codec.generate()) is wired — if the field is absent on insert, Drizzle calls codec.generate() to produce a new Id<Brand>.

Read path: normalises the raw DB string via codec.safeParse(), not strict is(). Throws IdsError("invalid_id") if the value from the database does not parse as a valid Id<Brand>.

Requires a codec that exposes synchronous generate() — see IdGeneratingCodec. Only the Timestamp codec and Reverse Timestamp codec qualify; Opaque, Signed, Wrapped, and Digest codecs are a compile-time error.

Brand extends string

IdGeneratingCodec<Brand>

The brand-scoped codec used to generate and parse values.

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.

HasRuntimeDefault<HasDefault<MySqlCustomColumnBuilder<{ columnType: "MySqlCustomColumn"; data: Id<Brand>; dataType: "custom"; driverParam: string; enumValues: undefined; name: ""; }>>>

import { generatedIdColumnMysql } from "@smonn/ids/drizzle";
import { createTimestampId } from "@smonn/ids";
const usr = createTimestampId("usr");
export const users = mysqlTable("users", { id: generatedIdColumnMysql(usr).primaryKey() });
// id is auto-filled on insert — no hand-supplied id needed