idField
idField<
Brand>(codec):object
Defined in: src/adapters/mikro-orm.ts:43
Returns a MikroORM property option object that wires codec.generate() into the
onCreate lifecycle hook, so the field auto-fills on first persist.
Requires a codec variant that exposes a synchronous generate() —
see IdGeneratingCodec. Only the Timestamp codec and Reverse
Timestamp codec qualify; Opaque, Signed, Wrapped, and Digest codecs cannot
be passed here.
Pass the result as options to @PrimaryKey() (the typical case for auto-generated primary keys) or any other MikroORM property decorator:
Type Parameters
Section titled “Type Parameters”Brand extends string
Parameters
Section titled “Parameters”IdGeneratingCodec<Brand>
Returns
Section titled “Returns”object
onCreate
Section titled “onCreate”onCreate: () =>
Id<Brand>
Returns
Section titled “Returns”Id<Brand>
type: () =>
Type<Id<Brand>,string>
Returns
Section titled “Returns”Type<Id<Brand>, string>
Example
Section titled “Example”import { PrimaryKey } from "@mikro-orm/core";import { idField } from "@smonn/ids/mikro-orm";import { createTimestampId } from "@smonn/ids";import type { Id } from "@smonn/ids";
const usr = createTimestampId("usr");
class User { @PrimaryKey(idField(usr)) id!: Id<"usr">;}