chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
626 stars 47 forks source link

Moving from `prisma-client` how do I query data? #126

Closed kjavia closed 1 year ago

kjavia commented 1 year ago

Hello. I am currently using prisma-client generator, and something like this.

import { Prisma, User } from '@prisma/client';

The prisma-client generator automatically adds the select, insert, and methods to the Prisma type.

I have replaced the prisma-client with zod-prisma-types generator as described in the documentation, but I don't anything about running actual queries with Prisma.

zod-prisma-types is no longer modifying the @prisma-client Prisma type. Is that still supposed to happen?

I am using Yarn with workspaces and a shared node_modules folder. Not sure if that's what breaking it.

kjavia commented 1 year ago

PS: I put back the original

generator prismaclient {
  provider = "prisma-client-js"
}

which I removed, now I have both zod and this. It seems to fix the issues.

chrishoermann commented 1 year ago

@kjavia you have to add both. The prisma-client generates the actual client you then interact with when querying the database and zod-prisma-types generates helper zod schemas that you can then use in your prisma queries mutations.