How to implement a transparent trading system (ie: prisma.js)?
P粉226413256
P粉226413256 2023-09-09 15:23:51
0
1
422

In the Prisma ORM documentation we can find the following example of grouping several database calls into a transaction. I would like to know how to implement the following. The method used in $transactions() (prisma.post...) is the same method we can use "standalone".

const [posts, totalPosts] = await prisma.$transaction([
  prisma.post.findMany({ where: { title: { contains: 'prisma' } } }),
  prisma.post.count(),
])

I want to know how to implement such a method ($transation()). My only idea is to check "context" (this), but not sure if that's the cleanest idea.

P粉226413256
P粉226413256

reply all(1)
P粉087074897

I'm not sure if I understand the question correctly. Are you trying to return the number of posts whose title contains the word "prisma"? If so, you should use the Interactive Trading API to achieve this.

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]
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!