Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/docs/src/routes/docs/integrations/prisma/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default component$(() => {

We will use `routeAction$` and `Form` to create a progressive form to add a new user to the DB. We will use `db.orm.public.User.create()` to create the user. It returns the inserted row.

The `email` column is unique, so creating a second user with the same email fails. PostgreSQL reports this as error code `23505`, which the action turns into a `409` response with a message for the form:
The `email` column is unique, so creating a second user with the same email fails. PostgreSQL reports this as error code `23505`, which the action turns into a `409` response with a message for the form. When `zod$` rejects the input, `failed` is also set and the messages are in `fieldErrors`, so the form shows either one:

```tsx {8} /db/ title="src/routes/create/index.tsx"
import { component$ } from '@qwik.dev/core';
Expand Down Expand Up @@ -230,7 +230,9 @@ export default component$(() => {
</label>
<button type="submit">Create</button>
</Form>
{createUserAction.value?.failed && <p>{createUserAction.value.message}</p>}
{createUserAction.value?.failed && (
<p>{createUserAction.value.message ?? createUserAction.value.fieldErrors?.email}</p>
)}
{createUserAction.value && !createUserAction.value.failed && (
<h2>User {createUserAction.value.name} created successfully!</h2>
)}
Expand Down