-
I'm wondering if I can use a prior Tx value in subsequent Tx queries: user, err := client.User.CreateOne(
db.User.Name.Set("USER NAME"),
).Tx()
post, err := client.Post.CreateOne(
db.Post.Title.Set("POST TITLE"),
db.Post.Content.Set("POST CONTENT"),
// Are we allowed to get `user` ID at this point?
db.Post.User.Link(user.Result().ID),
).Tx()
if err := r.DB.Prisma.Transaction(call, activeCall).Exec(ctx); err != nil {
panic('whoops')
} I know in Prisma js the transaction is an async function so you can do the Read, Modify, Write pattern, wondering if that's possible within Transactions in this library. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I believe whatever you can do with the JS transactions in the link you mentioned you should be able to do in the Go client as well. However, getting the result before running the transaction as per your example code will not work, and as far as I know will also not work with the JS client with the pattern you referred to – you'd rather not use transactions at all but use a different mechanism of making sure no conflicts can arise. This will be possible in JS using interactive transactions which is in preview right now but interactive transactions don't exist for the Go client yet (follow #569 for updates). Please do correct me if this is not right or if you meant something different. |
Beta Was this translation helpful? Give feedback.
-
That's exactly what I was looking for, and you're right I was referring to the JS preview feature. I will follow along for sure, it's not vital that I do it in a single operation, but it would help avoid edge cases and allow me to fail operations more gracefully. Also thanks for everything you're doing on this @steebchen, you're a powerhouse! I have been using Prisma in JS and just switched my Go code over to this, and I've found that this brings the same level of developer experience, so thanks for everything you're doing on this library. |
Beta Was this translation helpful? Give feedback.
I believe whatever you can do with the JS transactions in the link you mentioned you should be able to do in the Go client as well.
However, getting the result before running the transaction as per your example code will not work, and as far as I know will also not work with the JS client with the pattern you referred to – you'd rather not use transactions at all but use a different mechanism of making sure no conflicts can arise.
This will be possible in JS using interactive transactions which is in preview right now but interactive transactions don't exist for the Go client yet (follow #569 for updates).
Please do correct me if this is not right or if you meant something different.