Registry / database / drizzle-valibot

drizzle-valibot

JSON →
library0.4.2jsnpmunverified

Automatically generate Valibot validation schemas from Drizzle ORM table definitions. Current stable version 0.4.2, released in September 2024, with active development following Drizzle ORM releases. It bridges Drizzle's schema-first approach with Valibot's runtime validation, eliminating duplicated schema definitions. Unlike alternatives like drizzle-zod, it uses Valibot's composable and type-safe API. Requires Valibot >=1.0.0-beta.7 and Drizzle ORM >=0.36.0 as peer dependencies. Ships TypeScript types and supports PostgreSQL, MySQL, and SQLite.

npm install drizzle-valibot
INSTALL
IMPORT
SIG · DRIZZLE-VALIBOT
D
drizzle-valibot
databasejavascriptv0.4.2
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.

createSchema
import { createSchema } from 'drizzle-valibot'
import createSchema from 'drizzle-valibot'
Named export only; default import is not available. Works with both ESM and CJS.
pgSchema
import { pgSchema } from 'drizzle-valibot/pg'
import { pgSchema } from 'drizzle-valibot'
Database-specific helpers are in subpaths: '/pg', '/mysql', '/sqlite'. Main entry only exports generic 'createSchema'.
InferInputType
import type { InferInputType } from 'drizzle-valibot'
import { InferInputType } from 'drizzle-valibot'
Use 'import type' for type-only imports in TypeScript to avoid runtime overhead.

Creates a Drizzle table, generates Valibot schemas for insert and select, and validates an insert.

import { createTable, pgSchema } from 'drizzle-valibot/pg'; import { drizzle } from 'drizzle-orm/vercel-postgres'; import { sql } from '@vercel/postgres'; const schema = pgSchema('public'); const users = createTable(schema, 'users', { id: schema.serial('id').primaryKey(), name: schema.text('name').notNull(), email: schema.text('email').unique(), }); const { insertSchema, selectSchema } = createSchema(users); // Use insertSchema to validate input const result = insertSchema.parse({ name: 'John Doe', email: 'john@example.com' }); console.log(result); export { users, insertSchema, selectSchema };
Debug
Known issues
breakingRequires Valibot >=1.0.0-beta.7 (breaking changes in Valibot 1.0.0 beta).
fix
Upgrade Valibot to version 1.0.0-beta.7 or later.
affects: >=0.3.0
breakingRequires Drizzle ORM >=0.36.0 (breaking changes in Drizzle 0.36.0).
fix
Upgrade Drizzle ORM to version 0.36.0 or later.
affects: >=0.4.0
deprecatedThe 'pgSchema' export from main entry is deprecated; use 'drizzle-valibot/pg' instead.
fix
Change import to 'drizzle-valibot/pg'.
affects: >=0.2.0
gotchaSchema generation only works with Drizzle's table builder, not raw SQL schemas.
fix
Define tables using Drizzle's 'createTable' or 'pgTable' before using 'createSchema'.
affects: all
gotchaValibot v1.0.0 beta changed 'InferInput' to 'InferInputType'.
fix
Use 'InferInputType' and 'InferOutputType' from 'drizzle-valibot'.
affects: >=0.3.0
Errors
Common errors & fixes
Cannot find module 'drizzle-valibot' or its corresponding type declarations.
Missing package installation or incompatible version.
fix
Run 'npm install drizzle-valibot' and ensure peer dependencies are installed.
TypeError: drizzle_valibot_1.createSchema is not a function
Default import instead of named import.
fix
Change to 'import { createSchema } from 'drizzle-valibot''.
SchemaError: Table 'users' is not a Drizzle table. Use createTable or pgTable.
Passing a plain object instead of a Drizzle table definition.
fix
Define the table using Drizzle's table builder before calling 'createSchema'.
ValibotError: Expected object but received undefined.
Missing required fields in the input object.
fix
Ensure all 'notNull' fields are provided in the parsed data.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
valibotrequiredPeer dependency for runtime validation schema generation
drizzle-ormrequiredPeer dependency for Drizzle table definitions
Agent activity
31 hits · last 30 days
node
26
Amazon
1
OpenAI (training)
1
Resources
drizzle-valibot — npm install drizzle-valibot · libregistry