简体   繁体   中英

Prisma transaction in nodejs and typescript not working

I have 100 over record to update. So I use transaction but I got following error -:

Argument of type '(tx: any) => Promise' is not assignable to parameter of type 'PrismaPromise[]'. Type '(tx: any) => Promise' is missing the following properties from type 'PrismaPromise[]': pop, push, concat, join, and 28 more.

May I know how to solve?

await prisma.$transaction(async (tx :any) /*error here*/ => {

    const updateSong = await tx.songs.update({
      where: {
        id: d.id,
      },
      data: {
        duration: duration,
      },
    })

  })

I got the same error, I fix that with try add previewFeatures = ["interactiveTransactions"] and then regenrate your schema with npx prisma generate

Ey fam, previewFeatures = ["interactiveTransactions"] in your schema.prisma file. Should look like this:

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["interactiveTransactions"]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM