🔊 Added query logging for Prisma

This commit is contained in:
Axel Olausson Holtenäs 2022-10-23 22:33:16 +02:00
parent d624c62669
commit cf3f3449e8
No known key found for this signature in database
GPG key ID: BEDBB4D61E6C8462

View file

@ -1,3 +1,20 @@
import { PrismaClient } from '@prisma/client'
import { PrismaClient } from "@prisma/client";
import logger from "../../middlewares/logger";
export default new PrismaClient()
const prisma = new PrismaClient();
prisma.$use(async (params, next) => {
const before = Date.now();
const result = await next(params);
const after = Date.now();
logger.debug(
`Query ${params.model}.${params.action} took ${after - before}ms`
);
return result;
});
export default prisma;