
✅ findUnique
where에 지정한 조건이 맞는 user를 검색한다.
user = await client.user.findUnique({
where: {
email,
},
});
✅ create
data 내에 지정한 정보로 user를 생성한다.
user = await client.user.create({
data: {
name: "Anonymous",
email,
},
});
✅ upsert
update + insert를 합친 것
where에 적은 조건을 만족하는 유저가 존재한다면 update를 하고, 존재하지 않으면 create한다. (update를 하지 않을거면 비워둔다.)
const { phone, email } = req.body;
const payload = phone ? { phone: +phone } : { email };
const user = await client.user.upsert({
where: {
...payload,
},
create: {
name: "Anonymous",
...payload,
},
update: {},
});'💎 Prisma' 카테고리의 다른 글
| Prisma - Prisma v7 사용법 (0) | 2026.01.16 |
|---|---|
| Prisma - schema.prisma에서 model 깔끔하게 자동 정렬하기 (0) | 2025.09.24 |
| Prisma - User & Token connection (1) | 2025.06.02 |
| Prisma - 시작하기 (0) | 2025.05.26 |