drizzle-valibot
is a plugin for Drizzle ORM that allows you to generate valibot schemas from Drizzle ORM schemas.
Usage
import { pgEnum, pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';
import { createInsertSchema, createSelectSchema } from 'drizzle-valibot';
import { string, parse, number } from 'valibot';
const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
email: text('email').notNull(),
role: text('role', { enum: ['admin', 'user'] }).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
});
const insertUserSchema = createInsertSchema(users);
const selectUserSchema = createSelectSchema(users);
const insertUserSchema = createInsertSchema(users, {
role: string,
});
const insertUserSchema = createInsertSchema(users, {
id: (schema) => number([minValue(0)]),
role: string(),
});
const isUserValid = parse(insertUserSchema, {
name: 'John Doe',
email: 'johndoe@test.com',
role: 'admin',
});