Hello. I am always happy with the new features and...
# orm-help
d
Hello. I am always happy with the new features and I am using it well. I have a question. Currently, we are developing Serverless based on AWS Lambda. However, the following or similar warning messages are still occurring. - “Already 10 Prisma Clients are actively running.” Maybe serverless-offline creates a Prisma client again in the process of recompiling this file, but I don’t know the exact cause. The client is allocating as follows.
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
prisma.$use(async (params, next) => {
const bypassSoftDeleted: string[] = [];
if (params.model && !bypassSoftDeleted.includes(params.model)) {
if (!['create', 'update', 'upsert', 'delete'].includes(params.action)) {
if (!params.args.where) params.args.where = {};
if (!params.args.where['deletedAt']) {
params.args.where['deletedAt'] = null;
}
}
if (['delete', 'deleteMany'].includes(params.action)) {
if (params.action === 'delete') params.action = 'update';
if (params.action === 'deleteMany') params.action = 'updateMany';
if (!params.args.data) params.args.data = {};
params.args.data['deletedAt'] = new Date();
}
}
return next(params);
});
export { prisma };
The middleware above is a soft delete. Thanks for reading.
r
Maybe serverless-offline creates a Prisma client again in the process of recompiling this file
Yeah that’s most probably the case. Could you try this and see if that works? Also re-start the database so that old connections are killed.
🖤 1
d
Oh. thank you very much 🙂
👍 1