Hi everyone! How do I use Prisma inside of a monor...
# orm-help
j
Hi everyone! How do I use Prisma inside of a monorepo managed by Lerna? Multiple packages will depend on Prisma's types, so what do you advise?
Do I have to create a dedicated package for Prisma or can I just initialize it in the root of my project?
b
in our use case we have 2 api packages that have there types generated for each package using the
--schema=./schema.prisma'
in the generate command to point to same location, not sure if thats best practices but it works fine
j
@Ben so the schema.prisma file is located in the root?
b
we have it pulled into its own project at time being
j
Something like this?
b
we just have like
packages/db/schema.prsima
then in another package packages/api
wee call yarn generate inside thata
oh and we are using yarn with workspaces which may be different
Copy code
"workspaces": {
    "nohoist": [
      "@prisma/*"
    ]
  }
so we dont bring prisma up to root node modules
it will stay in that packages/api/node_modules folder
j
So
db
is considered a package too?
b
yeah
it just a folder really no package.json or anything
j
ow okay
I actually need the same schema but in 1 package I don't need any generators while in the other package I do
b
so in my messed up example i would call
Copy code
generate --schema=../db/schema.prisma'
or something similar
j
but where will it generate the types?
in db folder or in api?
b
it will generate its types for thee api folder since thats where i call that commaand
j
so you call the command in the api folder?
and what about dependencies like Prisma Client?
where did you add them to?
b
i call commanad where i want it to genereate client
@prisma/cli is in api folder right now
j
hhm and what if you need Prisma in another package?
then you need to add that dependency again?
b
we run generate in that folder too
issue we have which you might not haave is we have multiple data sources, so client may be different per package in our monorepo
j
ow alright that's indeed different
I only have 1 source, a PostgreSQL DB
j
What about having a db package where the index file just exports
@prisma/client
?
b
since your using lerna you could test to see if hoisting prisma to root works, and in your case thats all you need
j
so I should add it to the root package.json?
@Jonathan Romano Yeah I could try that