drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
22.13k stars 514 forks source link

[FEATURE]: Export factory functions from `drizzle-zod` to allow usage with extended Zod classes #2245

Open juliusmarminge opened 2 months ago

juliusmarminge commented 2 months ago

Describe what you want

To allow generating schemas from an extended Zod class, such as: https://github.com/honojs/middleware/tree/main/packages/zod-openapi

Currently, this doesn't work since generated schemas are using the default z object which will cause runtime errors if later combined with .openapi() from the lib above

Something like this would be nice

import { z } from '@hono/zod-openapi'
import { createInsertSchemaFactory } from 'drizzle-zod/factories'

import { User } from '~/schema'

const createInsertSchema = createInsertSchemaFactory(z);

const InsertUser = createInsertSchema(User)

// later

InsertUser.openapi() // works
d4mr commented 2 months ago

This would be very helpful. I don't understand how people use Hono with Drizzle without this, is everyone duplicating their source of truth?

Marley-Mulvin-Broome commented 1 month ago

Really need this +1