web3.news/app/lib/prisma.ts

25 lines
665 B
TypeScript
Raw Normal View History

import { PrismaClient, Article } from "@prisma/client";
2023-12-22 11:05:06 +00:00
import search from "./search.js";
const globalForPrisma = global as unknown as { prisma: PrismaClient };
2023-12-22 11:05:06 +00:00
export const prisma = (globalForPrisma.prisma || new PrismaClient()).$extends({
query: {
article: {
async create({ args, query }) {
// Perform the create operation using Prisma
const createdRecord = await query(args);
2023-12-22 11:05:06 +00:00
// Index the created record in MeiliSearch
const index = search.index("articles");
await index.addDocuments([createdRecord]);
return createdRecord;
},
},
},
});
export default prisma;
export type { Article };