How to get a plain row schema using drizzle-zod?

I am using these drizzle packages
"drizzle-orm": "0.40.0",
"drizzle-zod": "0.7.0",
"drizzle-kit": "0.30.5", (dev dependency)
"drizzle-orm": "0.40.0",
"drizzle-zod": "0.7.0",
"drizzle-kit": "0.30.5", (dev dependency)
I used drizzle kit to pull table schemas from a pg table I want to get a plain schema that represents a row in this table I tried this but cannot infer the type from this schema
export const amBrandSchema = createSelectSchema(table);
// This does not work
type AmBrandSchema = z.infer<typeof amBrandSchema>;
export const amBrandSchema = createSelectSchema(table);
// This does not work
type AmBrandSchema = z.infer<typeof amBrandSchema>;
The amBrandSchema seems to be of a type BuildSchema<"select",...> I would let to get a zod schema that is an object that represents a row of the table What am I doing wrong?
2 Replies
Antebios
Antebios4mo ago
Did you ever figure this out?
Valerka
Valerka4mo ago
@elyptica You can do this:
type AmBrandInsertSchema = typeof table.$inferInsert
type AmBrandSelectSchema = typeof table.$inferSelect
type AmBrandInsertSchema = typeof table.$inferInsert
type AmBrandSelectSchema = typeof table.$inferSelect
Docs: https://orm.drizzle.team/docs/latest-releases/drizzle-orm-v0283#-added-tableinferselect--table_inferselect-and-tableinferinsert--table_inferinsert-for-more-convenient-table-model-type-inference
Drizzle ORM - DrizzleORM v0.28.3 release
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.

Did you find this page helpful?