Registry / database / orchid-orm-schema-to-zod

orchid-orm-schema-to-zod

JSON →
library1.0.88jsnpmunverified

Converts Orchid ORM column schema definitions into Zod validation schemas, enabling reuse of column types for runtime validation. Current version is 1.0.88, actively maintained with releases following Orchid ORM updates. Key differentiator: automatically generates Zod schemas that match database column types (text, integer, boolean, timestamps, enums, etc.) without manual duplication. Supports TypeScript, integrates with Orchid ORM's table definitions, and handles nested validation methods like .nullable(), .default(), and .unique(). Alternative to manually writing Zod schemas aligned with database schema.

npm install orchid-orm-schema-to-zod
INSTALL
IMPORT
SIG · ORCHID-ORM-SCHEMA-
O
orchid-orm-schema-to-zod
databasejavascriptv1.0.88
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

schemaToZod
import { schemaToZod } from 'orchid-orm-schema-to-zod'
import schemaToZod from 'orchid-orm-schema-to-zod'
Library exports named export, not default. TypeScript: import type { schemaToZod } from 'orchid-orm-schema-to-zod' for types.
schemaToZod (CommonJS)
const { schemaToZod } = require('orchid-orm-schema-to-zod')
CommonJS require works, but ESM is preferred as library ships both CJS and ESM.
z (Zod schema)
import { z } from 'zod' const mySchema = schemaToZod(table.columns.myColumn)
The returned object is a Zod schema, so you can chain Zod methods like .refine() after conversion.

Creates a Zod schema from an Orchid ORM table definition, then validates an object.

import { schemaToZod } from 'orchid-orm-schema-to-zod' import { createTable, text, integer, timestamps } from 'orchid-orm' const table = createTable('user', (t) => ({ id: t.autoId(), name: t.text(3, 100).nullable(), age: t.integer(0, 120).default(0), ...t.timestamps(), })) const zodSchema = schemaToZod(table) const parsed = zodSchema.parse({ name: 'Alice', age: 30, createdAt: new Date(), updatedAt: new Date(), }) console.log(parsed) // { id: undefined, name: 'Alice', age: 30, ... } // For a single column: const nameSchema = schemaToZod(table.name) nameSchema.parse('Bob') // works nameSchema.parse(null) // passes because nullable nameSchema.parse(123) // throws ZodError
Debug
Known issues
gotchaschemaToZod returns a ZodObject for table schema, but for column reference it returns the column's Zod type directly (e.g., ZodString for text).
fix
When passing a column reference (table.user.name), expect a single Zod type, not an object.
affects: <2.0
gotchaTimestamps columns (createdAt, updatedAt) are converted to Zod.date() by default. If your DB returns strings, you may need additional transformation.
fix
Use Zod's .transform() or .pipe() to coerce strings to dates: schemaToZod(table).transform((val) => ({ ...val, createdAt: new Date(val.createdAt) }))
affects: <2.0
gotchaschemaToZod does not handle relations or foreign keys; it only converts column definitions.
fix
Define Zod schemas for relations separately or use Orchid ORM's query methods for validation.
affects: <2.0
deprecatedColumn methods like .unique() and .index() do not affect the Zod schema; they are for database schema.
fix
These methods are ignored during conversion; do not rely on them for validation.
affects: >=1.0
Errors
Common errors & fixes
TypeError: schemaToZod is not a function
Default import instead of named import.
fix
Use import { schemaToZod } from 'orchid-orm-schema-to-zod'
ZodError: Expected string, received number
Passing wrong type to a column schema.
fix
Ensure the value matches the column type: text expects string, integer expects number, boolean expects boolean.
Error: Table must be provided as first argument
Calling schemaToZod without arguments or with invalid input.
fix
Pass a table object or column reference as the argument: schemaToZod(table) or schemaToZod(table.name)
Cannot find module 'orchid-orm-schema-to-zod'
Package not installed or missing from node_modules.
fix
Run npm install orchid-orm-schema-to-zod (and ensure zod and orchid-orm are installed)
Upgrade
Version history
1.0.88latest on npm
Audit
Dependencies
zodrequiredPeer dependency - generates Zod schemas that depend on Zod at runtime
orchid-ormrequiredPeer dependency - consumes Orchid ORM column types (e.g., text(), integer())
Agent activity
7 hits · last 30 days
node
6
Resources
orchid-orm-schema-to-zod — npm install orchid-orm-schema-to-zod · libregistry