-
I want to inject a database service but did not find any way to do. How to solve it? For example, #711 mentioned the 'provide' option, like this: import { PrismaClient } from "@prisma/client";
// plugins/prisma.ts
export default defineNitroPlugin((nitroApp) => {
const prisma = new PrismaClient();
return {
provide: {
db: prisma
}
};
}); Any tips on how to implement it in the current version? |
Beta Was this translation helpful? Give feedback.
Answered by
manniL
Feb 3, 2023
Replies: 1 comment 2 replies
-
You can use a nitro middleware and do sth. like: import { PrismaClient } from '@prisma/client'
let prisma
export default defineEventHandler((event) => {
if (!prisma) {
prisma = new PrismaClient()
}
event.context.prisma = prisma
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
uyloal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use a nitro middleware and do sth. like: