search

Home  >  Q&A  >  body text

How to implement a transparent trading system (ie: prisma.js)?

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粉226413256P粉226413256449 days ago466

reply all(1)I'll reply

  • P粉087074897

    P粉0870748972023-09-10 10:47:07

    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]
    })
    

    reply
    0
  • Cancelreply