If you want a really nice API for your drizzle PG tables from Zod, such as:
import { inserts, select, enums } from './drizzle-zod-helpers'
const userType = enums.UserType.parse('admin')
// construct a type-safe insert
const userInsert = inserts.user.parse({
...user
})
const userSelect = selects.user.parse({
...user
})
// construct type-safe insert functions
async function createUser(user: Zod.infer<typeof inserts.user>) {
return await db.insert(schema.users).values(user).execute()
}
Be sure to install drizzle-zod
(and zod
)
yarn add drizzle-zod zod
Next, copy the TypeScript file from this Gist into your repo. Be sure to change the first line to point to your schema
file.