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

 

'Prisma' 카테고리의 다른 글

22.01.09 실용적인 프리즈마 예제 공유  (0) 2022.01.09
22.01.09 select fields(정리중)  (0) 2022.01.09
22.01.05 [prisma] Date.now()와 new Date()  (0) 2022.01.05
21.11.11 pagination  (0) 2021.11.12
21.11.02 prisma 설치하기  (0) 2021.11.04