Prisma
22.01.09 [prisma] CRUD update query
슈팅스타제제
2022. 1. 9. 19:32
update
update a single record
where에 해당하는 속성의 값을 하나만 업데이트해라
const updateUser = await prisma.user.update({
where: {
email: '9708jjw@gmail.com',
},
data: {
name: 'jemerald',
}
})
updateMany
update multiple records
where에 해당하는 속성의 값이 포함되어있다면 모두 업데이트해라!
const updateUsers = await prisma.user.updateMany({
where:{
email:{
contains:'prisma.io',
}
},
data:{
role:'ADMIN',
}
})
upsert
update or create records
where에 해당하는 속성의 값이 없다면 create 하고 있다면 해당 값으로 업데이트해라!
const upsertUser = await prisma.user.upsert({
where:{
email:'9708jjw@gmail.com,
},
update:{
name:'jemerald',
},
create:{
email:'9708jjw@gmail.com',
name:'jemerald',
}
})
참고문서링크:
https://www.prisma.io/docs/concepts/components/prisma-client/crud#update
CRUD (Reference)
How to perform CRUD with Prisma Client.
www.prisma.io