NuxtN
Nuxt2y ago
Medim

Use prisma globally in api routes

I have a question, is it possible to use the prisma client globally without having to import it everytime? I'm using Prisma + Turso so there's a bit more than just two lines of code to use the prisma client so adding it to every api file is a bit tiring, is there a way to make it available as a util/helper globally?
what is the best way to do it?

import { PrismaClient } from "@prisma/client"
const libsql = createClient({
  url: `${tursoDatabaseUrl}`,
  authToken: `${tursoAuthToken}`,
})

const adapter = new PrismaLibSQL(libsql)
const prisma = new PrismaClient({ adapter })
Was this page helpful?