idType
idType<
Brand>(codec,options?): () =>Type<Id<Brand>,string>
Defined in: src/adapters/mikro-orm.ts:96
Factory that returns a MikroORM Type subclass bound to a codec.
Write path (convertToDatabaseValue): validates the value via
codec.safeParse and throws IdsError("invalid_id") if validation fails.
Read path (convertToJSValue): normalises the raw DB value via
codec.safeParse(). Throws IdsError("invalid_id") if the stored value
does not parse as a valid Id<Brand>.
Column type (getColumnType): returns "text" by default, or the
options.columnType override when provided.
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”() => Type<Id<Brand>, string>
Example
Section titled “Example”import { PrimaryKey } from "@mikro-orm/core";import { idType } from "@smonn/ids/mikro-orm";import { createTimestampId } from "@smonn/ids";import type { Id } from "@smonn/ids";
const usr = createTimestampId("usr");
// default: text columnclass User { @PrimaryKey({ type: idType(usr) }) id!: Id<"usr">;}
// explicit varchar columnclass Org { @PrimaryKey({ type: idType(usr, { columnType: "varchar(30)" }) }) id!: Id<"usr">;}