Domains
Creating a Postgres Domain Type in your schema will add this data type to your domains directory.
CREATE DOMAIN TEXT_SHORT AS TEXT CONSTRAINT check_length CHECK (LENGTH(value) <= 255);Directoryno-orm
Directorypublic
Directorydomains
- schemas.ts
- types.ts
This generates a Zod schema which can parse the enum from your database:
export const textShort = z.string().brand<"public.domains.text_short">();import * as Schemas from "./schemas";
export type TextShort = z.infer<typeof Schemas.textShort>;Note that domains are scoped on a per-schema level (e.g public).
Validating domains
Section titled “Validating domains”You might have noticed that even though the domain data type enforces that the string is <= 255 characters, the no-orm generated Zod schema does not do this.
no-orm is not that smart.
Instead, you have to write your own Zod schemas to validate input before it can be written to the database:
import * as Domains from "@no-orm/public/domains";import { z } from "zod";
export const schema = z.string().max(255).pipe(Domains.Schemas.textShort);
...
export const createPenguinRequestBody = z.object({ name: z.string().pipe(Schemas.TextShort.schema), ...)};...Creating a row in a table that uses the TEXT_SHORT data type will give you a Typescript compiling error unless it is first parsed into a branded TextShort type.
You can see this being used in the example server here.