简体   繁体   中英

Atomic update Mutation using Prisma

What would be the best way to atomically update a node using its an existing value (get-and-update)? Seems like the update node Mutation does not have an option of receiving an update-if-exists function.

Locking the object with a write lock, getting the value, updating it and releasing the lock might work but would cause complexity and lots of faulty code I'm trying to avoid.

I'm using MySql with Prisma connector for node.js with a .prisma datamodel.

Transactions in Prisma aren't implemented yet. However there is some issues opened in their github about this:

  • Transactions for multiple operations ( #74 )
  • Transactions for long running operations with dependencies between write operations ( #3846 )

Prisma 2.1.0 released the first experimental version of transactions via Promises.

Here is the official documentation docs

const write1 = prisma.user.create()
const write2 = prisma.post.create()
const write3 = prisma.profile.create()
await prisma.$transaction([write1, write2, write3])

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