GET
database.[model]명.findUnique()
- 유니크한 값 (pk 등)을 통해 데이터를 찾음
const user = await database.user.findUnique({
where : {
id: "id값을 넣어주세요"
}
select : {
id : true,
nmae : true
}
}); // where => 해당 id값의 유저의 , select => id값과 name을 가져옴
database.[model]명.findFirst()
- 조건에 맞는 데이터 중 가장 최근 데이터 찾음
const user = await databse.user.findFirst({
where : {
name : "이름을 넣어주세요"
}
});
database.[model]명.findMany()
- 조건에 맞는 데이터를 모두 찾음
const users = await database.user.findMany({
where : {
name : "이름을 넣어주세요"
}
});
where - OR
- 배열 안의 조건을 하나라도 만족하는 데이터 찾음
const users = await database.user.findMany({
where : {
OR:[
{
name : "이름을 넣어주세요"
},
{
age : 20
},
],
},
});
orderBy
- 해당 컬럼 기준으로 desc(내림차순)/asc(오름차순)으로 불러옴
const user = await database.user.findMany({
where : {
name : "id값을 넣어주세요.",
},
orderBy : {
age : "desc",
},
});