Registry / database / drizzle-typebox

drizzle-typebox

JSON →
library0.3.3jsnpmunverified

Generates Typebox JSON Schema validation schemas directly from Drizzle ORM table definitions. As of v0.3.3, it works with Drizzle ORM >=0.36.0 and Typebox >=0.34.8. This eliminates duplication between database schema defined in Drizzle and runtime validation schemas, ensuring single-source-of-truth for types and validation. Compared to alternatives like Zod or Yup, Typebox offers faster validation and smaller bundles, making it ideal for performance-critical environments. The package is maintained by the Drizzle team with regular releases aligned with Drizzle ORM updates.

npm install drizzle-typebox
INSTALL
IMPORT
SIG · DRIZZLE-TYPEBOX
D
drizzle-typebox
databasejavascriptv0.3.3
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.

drizzleTypebox
import { drizzleTypebox } from 'drizzle-typebox'
const { drizzleTypebox } = require('drizzle-typebox')
Package is ESM-only since v0.1.0; CommonJS require() will fail.
Type
import { Type } from '@sinclair/typebox'
import { Type } from 'drizzle-typebox'
Typebox's Type utility is re-exported from drizzle-typebox for convenience, but direct import from '@sinclair/typebox' is preferred for clarity.
buildInsertSchema
import { buildInsertSchema, buildSelectSchema } from 'drizzle-typebox'
import { buildSchema } from 'drizzle-typebox'
There is no default 'buildSchema' export; use explicit insert/update/select builders.
typeboxTableToTypes
import { typeboxTableToTypes } from 'drizzle-typebox'
Generates TypeScript type definitions from generated Typebox schemas (v0.3.0+).

Creates Typebox insert and select schemas from a Drizzle PostgreSQL table definition.

import { drizzleTypebox } from 'drizzle-typebox'; import { Type } from '@sinclair/typebox'; import { pgTable, integer, varchar } from 'drizzle-orm/pg-core'; const users = pgTable('users', { id: integer('id').primaryKey(), name: varchar('name', { length: 255 }), email: varchar('email', { length: 255 }), }); const { buildInsertSchema, buildSelectSchema } = drizzleTypebox(); const insertUserSchema = buildInsertSchema(users); console.log(Type.String()); // insertUserSchema is a Typebox schema: Type.Object({ ... }) const selectUserSchema = buildSelectSchema(users); // selectUserSchema is a Typebox schema for SELECT results
Debug
Known issues
breakingESM-only: package does not support CommonJS require().
fix
Use import syntax or switch to an older version if CJS is required.
affects: >=0.1.0
deprecatedThe function `typeboxToTable` was renamed to `typeboxTableToTypes` in v0.3.0.
fix
Use `typeboxTableToTypes` instead.
affects: >=0.3.0 <0.3.0
gotchaDefault export drizzleTypebox() must be called as a function; returns an object with builder methods.
fix
Use `const { buildInsertSchema } = drizzleTypebox();` not `import { drizzleTypebox } from ...` then direct call.
affects: >=0.1.0
gotchaDo not pass null or undefined column names; Typebox schemas will be incomplete or error.
fix
Ensure all columns used in generated schemas have names defined in the Drizzle table.
affects: >=0.1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using CommonJS require() on an ESM-only package.
fix
Change to import syntax: `import { drizzleTypebox } from 'drizzle-typebox'` or set `type: 'module'` in package.json.
TypeError: drizzleTypebox is not a function
Treating named export 'drizzleTypebox' as a static value instead of calling it as a function.
fix
Call the function: `const { buildInsertSchema } = drizzleTypebox();`
Error: Cannot find module '@sinclair/typebox'
Missing peer dependency @sinclair/typebox.
fix
Install peer dependency: `npm install @sinclair/typebox`
Upgrade
Version history
0.3.3latest on npm
Audit
Dependencies
drizzle-ormrequiredpeer dependency for Drizzle ORM types and schema definitions
@sinclair/typeboxrequiredpeer dependency for Typebox schema generation
Agent activity
10 hits · last 30 days
node
8
Resources
drizzle-typebox — npm install drizzle-typebox · libregistry