From 84b35b3fe52b5000bfc5286eabd32f92857ec3e2 Mon Sep 17 00:00:00 2001 From: Yunus <19399214+yunusefendi52@users.noreply.github.com> Date: Sun, 31 Mar 2024 14:54:10 +0700 Subject: [PATCH] Okk --- server/middleware/00.start.ts | 4 ++-- server/plugins/startup.ts | 4 ++++ server/services.ts | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 server/services.ts diff --git a/server/middleware/00.start.ts b/server/middleware/00.start.ts index 2280e4f..63f3f05 100644 --- a/server/middleware/00.start.ts +++ b/server/middleware/00.start.ts @@ -1,4 +1,5 @@ import { PrismaClient } from '@prisma/client' +import { services } from '../services'; declare module 'h3' { interface H3EventContext { @@ -7,6 +8,5 @@ declare module 'h3' { } export default defineEventHandler(async (event) => { - const prisma = new PrismaClient() - event.context.prisma = prisma + event.context.prisma = services.prisma }) diff --git a/server/plugins/startup.ts b/server/plugins/startup.ts index 1c183df..cfcb7bc 100644 --- a/server/plugins/startup.ts +++ b/server/plugins/startup.ts @@ -1,2 +1,6 @@ +import { PrismaClient } from "@prisma/client" +import { services } from "../services" + export default defineNitroPlugin(async (nuxtApp) => { + services.prisma = new PrismaClient() }) diff --git a/server/services.ts b/server/services.ts new file mode 100644 index 0000000..03d2044 --- /dev/null +++ b/server/services.ts @@ -0,0 +1,7 @@ +import type { PrismaClient } from "@prisma/client"; + +class Services { + prisma!: PrismaClient; +} + +export const services = new Services()