Jacob
Jacob
Explore posts from servers
DTDrizzle Team
Created by Jacob on 11/3/2023 in #help
[BUG]: React Hook Form doesn't submit when using drizzle-zod to create schemes to use in zodResolver
When using drizzle-zod to generate schemas from database schemas and using them in the useForm resolvers the onSubmit won't fire at all for some reason, So for example:
export const userSchema = createInsertSchema(users);
export const userSchema = createInsertSchema(users);
and then using it in the useForm
const { handleSubmit, register, control, getValues } = useForm<User>({
resolver: zodResolver(userSchema),
defaultValues: async () => {
const res = await fetch(`/api/users/`)
const user = (await res.json()) as User;
return user;
},
});

const onSubmit: SubmitHandler<User> = async (data) => {
console.log(data)

await fetch('/api/users/updateUser', {
method: "PUT",
body: body: JSON.stringify(data),
})
};
const { handleSubmit, register, control, getValues } = useForm<User>({
resolver: zodResolver(userSchema),
defaultValues: async () => {
const res = await fetch(`/api/users/`)
const user = (await res.json()) as User;
return user;
},
});

const onSubmit: SubmitHandler<User> = async (data) => {
console.log(data)

await fetch('/api/users/updateUser', {
method: "PUT",
body: body: JSON.stringify(data),
})
};
in this example when you click the Submit from the form it doesn't work at all. however if you build your own schema using zod it works fine. For reference this was working about a about a week ago. No errors show in the browser console or terminal, so i don't know what is up there I have posted issues on react-hook-form and drizzle-orm however I'm not sure which team is that the problem is coming from https://github.com/react-hook-form/resolvers/issues/642 https://github.com/drizzle-team/drizzle-orm/issues/1448 To Reproduce Steps to reproduce the behavior: 1. create a schema using zod 2. create a zod schema using drizzle-zod and createInsertSchema 3. import that schema into a useForm resolver 4. try submitting the form (should not work) Codesandbox link very simple application that doesn't seem to submit: https://codesandbox.io/p/sandbox/react-hook-form-zod-resolver-not-working-9c7qn9 Environment & setup Operating systems that is is occuring in: - Mac ventura 13.5.2, - Windows 10 - Windows 11 - Codesandbox Browsers: - Chrome Versions of packages: - react-hook-form: 7.47.0 - @hookform/resolvers: 3.3.2 - drizzle-orm: 0.28.6 - drizzle-zod: 0.5.1 - drizzle-kit: 0.19.13
1 replies
DTDrizzle Team
Created by Jacob on 8/11/2023 in #help
Running into an error when runing `drizzle-kit push:mysql` yet i haven't changed anything
So i seem to be running into this error:
$ pnpm db:push

> [email protected] db:push G:\GitHub\Meally\apps\meally
> drizzle-kit push:mysql --config=drizzle.config.ts

drizzle-kit: v0.19.8
drizzle-orm: v0.27.2

Reading config file 'G:\GitHub\Meally\apps\meally\drizzle.config.ts'
Reading schema files:
G:\GitHub\Meally\apps\meally\src\db\schemas\auth.ts
G:\GitHub\Meally\apps\meally\src\db\schemas\enums.ts
G:\GitHub\Meally\apps\meally\src\db\schemas\groups.ts
G:\GitHub\Meally\apps\meally\src\db\schemas\index.ts
G:\GitHub\Meally\apps\meally\src\db\schemas\recipe.ts

errno: 1067,
sql: 'ALTER TABLE `recipes` MODIFY COLUMN `isPublic` boolean;',
sqlState: '42000',
sqlMessage: `target: meally.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'createdAt' (errno 1067) (sqlstate 42000) (CallerID: 9d6l772g9pp919ug46mn): Sql: "alter table recipes modify column isPublic boolean", BindVars: {REDACTED}`
}
$ pnpm db:push

> [email protected] db:push G:\GitHub\Meally\apps\meally
> drizzle-kit push:mysql --config=drizzle.config.ts

drizzle-kit: v0.19.8
drizzle-orm: v0.27.2

Reading config file 'G:\GitHub\Meally\apps\meally\drizzle.config.ts'
Reading schema files:
G:\GitHub\Meally\apps\meally\src\db\schemas\auth.ts
G:\GitHub\Meally\apps\meally\src\db\schemas\enums.ts
G:\GitHub\Meally\apps\meally\src\db\schemas\groups.ts
G:\GitHub\Meally\apps\meally\src\db\schemas\index.ts
G:\GitHub\Meally\apps\meally\src\db\schemas\recipe.ts

errno: 1067,
sql: 'ALTER TABLE `recipes` MODIFY COLUMN `isPublic` boolean;',
sqlState: '42000',
sqlMessage: `target: meally.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'createdAt' (errno 1067) (sqlstate 42000) (CallerID: 9d6l772g9pp919ug46mn): Sql: "alter table recipes modify column isPublic boolean", BindVars: {REDACTED}`
}
This has only just been happening since about the last drizzle update, i have tried changing my schema with no luck. My version of drizzle and drizzle-kit
"drizzle-orm": "^0.27.2",
"drizzle-kit": "^0.19.8",
"drizzle-orm": "^0.27.2",
"drizzle-kit": "^0.19.8",
Please find my schema attached below:
10 replies