Hello everyone, We’re currently recreating a js/ex...
# orm-help
j
Hello everyone, We’re currently recreating a js/express microservice backend in ts/nestjs. Early in january I testd prisma vs typeorm and was impressed. Though I only tested it in a small monolithic environment. Now we got multiple microservices build with the nestjs microservice architecture and a gateway, glueing the services to a rest api. the problem i now see is that all the types are generated in the services. if i want to type the functions in the gateway or use swagger then i have to rewrite every type. is there an easy way to export generated types to put them into a npm module? was this use case considered?
j
We do something along these lines, we have different apps accessing a shared prisma library to get types.
Copy code
apps/a
apps/b
libs/prisma-schema/ (all our db schema here, this might not be required)
libs/nest-prisma (our generic nestjs module for instaniating prisma)
our apps import from a private package for types
Copy code
import type { User } from '@acmecorp/prisma'
and can import the service if needed
Copy code
import { PrismaService } from '@acmecorp/nest-prisma'
So it's use-case works for us, but will really depend on your tooling for monorepos.
j
you managed to outsource the service to an npm module? i tried that also, but encountered problems… i’ll give it another shot! two questions regarding your solution: 1. if you have a “users” service with a “users” entity, will you use the types from prisma-clientt or your package in the “users” service? 2. have you automated the export? there are two ways this can be solved in my opinion: a. make a script, that pulls the types from the client into another dir containing the npm modules src b. maybe more elegant: change the dir of where the types get generated by prisma to the dir of the npm module and locally link it
t
In my company, we have a private NPM package that contains our prisma types, client, etc. We can then import that package into any other repo we want. It has worked quite well for us.