在 Prisma ORM 文档中,我们可以找到以下将几个数据库调用分组到一个事务中的示例。我想知道如何实施以下内容。 $transactions() (prisma.post...) 中使用的方法与我们可以使用“独立”的方法相同。
const [posts, totalPosts] = await prisma.$transaction([
prisma.post.findMany({ where: { title: { contains: 'prisma' } } }),
prisma.post.count(),
])
我想知道如何实现这样的方法($transation())。
我唯一的想法是检查“上下文”(this),但不确定这是否是最干净的想法。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我不确定我是否正确理解了这个问题。 您是否试图返回标题包含“prisma”一词的帖子数?如果是这样,您应该使用交互式交易 API 来实现这一点。
const [posts, totalPosts] = await prisma.$transaction(async (prisma) => { const posts = await prisma.post.findMany({ where: { title: { contains: 'prisma' } } }) const count = prisma.post.count({ where: { title: { contains: 'prisma' } } }) return [posts, count] })