I reach to a point on where I need some external h...
# orm-help
d
I reach to a point on where I need some external help. I'm trying to use prisma to feed two different apps that are hosted in the same monorepo. I'm using turborepo as my mono and one app is a web app, and the other one is a terminal (CLI). Both are supposed to the same prisma schema and generated client to interact with the DB (postgres) so I thouhg it would be nice to abstract it an place prisma into it's own shared library in the mono. All in all, this was thought as very simple but it is giving me a lot of problems. Do you know if there is an example fo prisma working kind of like this way under a mono to where I can look for?
r
Hi @Demian N - what are the problems you are experiencing? AFAIK it should a case of setting up a single prisma instance and then importing that into your web app and cli? /lib/prisma.ts
Copy code
import { PrismaClient } from '@prisma/client';

export const prisma = new PrismaClient();
web:
Copy code
import {prisma} from "../lib/prisma";
cli (same basically):
Copy code
import {prisma} from "../lib/prisma";
or does that not work?
d
Yes, I'm doing that and I'm also exporting some extra types for the models. Now it seems to be working. I was having a silly type in the name of one of declaration files (small blank space within the extension). I need to check the NextJS app still but seems I'm again on the right path
This is aimed to prevent the duplication of code meaning the same schema and hence similar CRUD functions are used but both the app and the CLI. Thus it looks natural to place prisma into it's own library
r
yeah - I'd say that was the correct place too ..