Search code examples
node.jstypescriptexpressmicroservicesprisma

Share Prisma Types Between Microservices


I'm working on a project right now that has multiple TypeScript microservices performing operations on the same database. In each microservice, we are using the Prisma client to perform database operations. The issue I'm experiencing is we need to duplicate our schema.prisma file in each microservice and generate the Prisma client for each service. Is there a way to manage our database in a separate project while sharing the generated client between the microservices without having duplicate schema.prisma in each project?


Solution

  • prisma generates a client from the schema. This client is as far as im aware totally independent of the schema files and the prisma package. If you copy those generated files in any way, you can reuse the client in a different project.

    There is a nice article on medium using npm packages I guess. https://isidoro-ferreiro.medium.com/share-your-prisma-client-across-projects-44d1c7aca6fd

    However u could also use something like nodemon or your ci pipeline to copy the generated client files to the other services.