Skip to content

Instantly share code, notes, and snippets.

@pantharshit00
Created December 23, 2021 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pantharshit00/91b8532c0a1e9cc8e7715af44c0f8894 to your computer and use it in GitHub Desktop.
Save pantharshit00/91b8532c0a1e9cc8e7715af44c0f8894 to your computer and use it in GitHub Desktop.
Prisma middleware example
import { PrismaClient } from "@prisma/client";
import slugify from "slugify";
async function main() {
const prisma = new PrismaClient();
prisma.$use(async (params, next) => {
// Manipulate params here
if (params.model == "Project" && params.action == "create") {
params.args.data.slug = slugify(params.args.data.name);
}
const result = await next(params);
// See results here
return result;
});
const data = await prisma.project.create({
data: { name: "My project" },
});
console.log(data);
prisma.$disconnect();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment