【问题标题】:Prisma transaction in nodejs and typescript not workingnodejs和打字稿中的Prisma事务不起作用
【发布时间】:2022-01-15 04:33:28
【问题描述】:

我有 100 多条记录要更新。所以我使用事务,但出现以下错误 -:

“(tx: any) => Promise”类型的参数不能分配给“PrismaPromise[]”类型的参数。 类型 '(tx: any) => Promise' 缺少类型 'PrismaPromise[]' 中的以下属性:pop、push、concat、join 等 28 个。

我可以知道如何解决吗?

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

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

  })

【问题讨论】:

  • 您是否启用了交互式交易功能?
  • 是的。这里是。生成器客户端 { provider = "prisma-client-js" previewFeatures = ["interactiveTransactions"] }

标签: node.js typescript prisma


【解决方案1】:

我遇到了同样的错误,我尝试添加 previewFeatures = ["interactiveTransactions"] 来修复它 然后使用npx prisma generate重新生成架构

【讨论】:

  • 感谢您的回答。从 for 循环中取出 async 关键字后,我解决了这个问题。
【解决方案2】:

previewFeatures = ["interactiveTransactions"] 位于您的 schema.prisma 文件中。应该是这样的:

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

【讨论】:

    猜你喜欢
    • 2020-08-12
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2016-06-16
    • 2018-12-25
    • 1970-01-01
    相关资源
    最近更新 更多