Raj*_*ing 11 postgresql prisma
我有以下 prisma.schema:
model Tag {
id Int @id @default(autoincrement())
name String @unique
files FileTag[]
}
model FileTag {
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
tagId Int
file File @relation(fields: [fileId], references: [id], onDelete: Cascade)
fileId Int
@@id([fileId, tagId])
}
Run Code Online (Sandbox Code Playgroud)
这是我更新数据库的代码:
for (const tagId of tagIds){
const tag = await Tags.addFileToTag(parseInt(tagId), fileId);
};
async addFileToTag(tagId: number, fileId: number) {
const client = await getDbClient();
return await client.tag.update({
where: {
id: tagId,
},
data: {
files: {
create: {
fileId
}
}
}
})
}
Run Code Online (Sandbox Code Playgroud)
通过这次实施,我的目标达到了。但问题是,我不喜欢这种实现。我正在使用循环并重复调用相同的更新查询。
现在,我想知道是否有任何替代程序(即将 prisma update更改为updateMany查询)通过删除循环...这将对数据库进行相同的更改?
| 归档时间: |
|
| 查看次数: |
26703 次 |
| 最近记录: |