I know that many upsert queries don't exist. Any g...
# orm-help
k
I know that many upsert queries don't exist. Any good many(multiple) upsert examples? I wrote the code like this Do you have any other good way? code # 3 - Is there a problem with using promise.all ?
r
@kkangsan 👋 If you care about rolling back all upserts in case of an error, then approach #2 is the way to go. In approach #3 you will get a faster output but you need to perform the retry of failed items yourself with an error handling mechanism.
💯 1
👍 1
If you don’t have a lot of users, I would suggest going for #2.
👍 1
💯 1
k
@Ryan thanks for answering! If the example in #2 is the most useful, most for-loop await can be replaced with $transaction .
💯 1
r
Yes 💯
👍 1
😀 1
k
@Ryan I don't know much about $transaction, so I have one more question. Is it correct to rollback the entire $transaction if any query fails?
r
Depends on your use case. If the upserts are related to each other then you should rollback, otherwise it’s fine to not use a transaction 🙂
k
If each is unrelated, is it okay to use promise.all (#3) ?
Does prisma manage the connection pool well? Does using promise.all work without problems?
Depending on the number of queries, can too many be a problem with a wait timeout?
Lots of questions. I'm sorry. 😅
r
Promise.all
shouldn’t be a problem but as I said, you need to retry the failed items yourself using a retry mechanism.
😀 1
👍 1
💯 1
Depending on the number of queries, can too many be a problem with a wait timeout?
How many queries in this case?
k
about 10,000 to 20,000.
Sorry, I understand what you said earlier.
Promise.all
 shouldn’t be a problem but as I said, you need to retry the failed items yourself using a retry mechanism.
r
What if a single record fails in
Promise.all
? The records after that will not be processed so you need to have a mechanism of retrying those.
k
If I do Promise.allSettled , I think I can filter successful and failed queries with a filter.
To retry considering query failure, using $transaction seems to be the easiest way.😄
If multiple upserts occur frequently, I thought it would be better for performance to use promise.allSettled .🤔
r
Yeah that should be fine.
✅ 1
💯 1
k
@Ryan Thanks for the comment!
💯 1