Skip to content

nullableIdTransformer

nullableIdTransformer<Brand>(codec): ValueTransformer

Defined in: src/adapters/typeorm.ts:141

TypeORM column transformer for a nullable Id<Brand> column.

Behaves like idTransformer but from returns null for null / undefined database values and to passes null / undefined through unchanged. Use for optional foreign keys.

Brand extends string

IdColumnCodec<Brand>

ValueTransformer

import { nullableIdTransformer } from "@smonn/ids/typeorm";
import { createTimestampId } from "@smonn/ids";
import type { Id } from "@smonn/ids";
import { Column, Entity } from "typeorm";
const usr = createTimestampId("usr");
@Entity()
class Post {
@Column({ type: "text", nullable: true, transformer: nullableIdTransformer(usr) })
authorId!: Id<"usr"> | null;
}