hello I wanted to know do i have to remake the pri...
# orm-help
c
hello I wanted to know do i have to remake the prisma client for ever file that uses it?
m
You should abstract away the Prisma Client API into a service. Here's how they recommend doing it for NestJS. https://docs.nestjs.com/recipes/prisma#use-prisma-client-in-your-nestjs-services
c
Right now i'm using it with context.prisma with appollo server but i wanted to make utilities that returned bools or values
m
Can you give an example?
s
I have a file called
client.ts
with the following:
Copy code
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export default prisma;
I then import it in the individual files I need it like so:
Copy code
import prisma from "./client.js";
And then use it as follows:
Copy code
const deletedEntry = await prisma.targetWord.delete({ where: { id } });
For the most part you will never need to manage connecting, disconnecting, etc. https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/connection-management