DT
Drizzle Team•10mo ago
c0ldh4ck

Help with Drizzle-zod

Hi all, Working with SvelteKit I have a types/index.ts file in my lib folder. I want to create Schema and Types for zod validations for forms this way: import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; import { locations } from '$lib/server/database/schema'; export const insertLocationSchema = createInsertSchema(locations); export const selectLocationSchema = createSelectSchema(locations); export type insertLocationType = typeof insertLocationSchema; export type selectLocationType = typeof selectLocationSchema; I am getting an error that I cannot import server side code into client side components, which I understand. But I have my schema and all other DB relatated setup in $lib/server folder. How would I manage to use these types in for example a 'Create Location Form' component? I am using sveltekit-superforms and returning that via a +page.server.ts, I am a bit confused. Hopefully someone has some experience with SvelteKit and this
1 Reply
c0ldh4ck
c0ldh4ckOP•10mo ago
Using this in my types file works fine ofcourse: export const insertLocationSchema = z.object({ name: z.string().min(1, { message: 'Please fill in your location name' }), address: z.string().min(1, { message: 'Please fill in your location address' }), phone: z.string().min(1, { message: 'Please fill in your location phone number' }) }); export type newLocation = typeof insertLocationSchema; But I do not want to type it again 😕
Want results from more Discord servers?
Add your server