Replies: 3 comments
-
|
Not with a single schema definition — Drizzle intentionally uses separate table builders for each dialect ( However, you can share validation schemas and TypeScript types across both: 1. Shared types via
|
Beta Was this translation helpful? Give feedback.
-
|
Thank you for your reply. Does Drizzle have any plan to provide a way to create a unified schema for all databases, such as Prisma? In example something like this
instead of like a general way |
Beta Was this translation helpful? Give feedback.
-
|
Good question. Based on Drizzle's design philosophy and public roadmap, a Prisma-style unified schema isn't planned. Drizzle is intentionally SQL-first — it wants you to think in terms of the actual database you're targeting, not an abstraction layer over it. The rationale is that PostgreSQL, SQLite, and MySQL have meaningfully different capabilities:
A unified That said, the practical workaround for your use case is to define a shared contract and derive dialect schemas from it: // shared/schema.ts — your source of truth
import { z } from 'zod';
export const UserSchema = z.object({
id: z.string().uuid(),
name: z.string().min(1),
email: z.string().email(),
});
export type User = z.infer<typeof UserSchema>;// db/pg-schema.ts
import { pgTable, uuid, text } from 'drizzle-orm/pg-core';
export const users = pgTable('users', {
id: uuid('id').primaryKey().defaultRandom(),
name: text('name').notNull(),
email: text('email').notNull(),
});// db/sqlite-schema.ts
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
export const users = sqliteTable('users', {
id: text('id').primaryKey(), // no native uuid in SQLite
name: text('name').notNull(),
email: text('email').notNull(),
});The Zod schema validates at the application boundary (API input, form data), and the Drizzle schemas handle the database layer. Types stay in sync via It's more boilerplate than Prisma's approach, but it's a deliberate tradeoff for SQL fidelity. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to create just one schema to use for all of these? (Zod, PostgreSQL, Sqlite)
Beta Was this translation helpful? Give feedback.
All reactions