[英]How is .upsertMany() implemented in Prisma ORM?
Prisma ORM 具有更新或創建upsert()
方法的實現和一組批量請求,
但是沒有.upsertMany()
這樣的東西,即批量“創建或更新現有記錄”。
使用Prisma ORM實現這種方法的最佳方法是什么?
Prisma 本身不支持upsertMany
。
有一個功能請求提供upsertMany
方法。
截至目前,最好的方法是循環遍歷數據並在循環中調用upsert
以及使用$transaction
。
例子:
const collection = await prisma.$transaction(
userData.map(cur =>
prisma.cur.upsert({
where: { id: cur.id },
update: {},
create: { id: cur.id },
})
)
)
這是對$transaction API 的引用,應該會有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.