const getUser: User | null = await prisma.user.findUnique({
where: {
id: 22,
},
})
/*
{
id: 22,
name: "Alice",
email: "alice@prisma.io",
profileViews: 0,
role: "ADMIN",
coinflips: [true, false],
}
*/
const getUser: object | null = await prisma.user.findUnique({
where: {
id: 22,
},
select: {
email: true,
name: true,
},
})
/*
{
name: "Alice",
email: "alice@prisma.io",
}
*/
const users = await prisma.user.findMany({
select: {
name: true,
posts: {
select: {
title: true,
},
},
},
})
/*
{
name: "Alice",
email: "alice@prisma.io",
}
*/
const users = await prisma.user.findMany({
// user의 모든 필드를 가져올 때 사용
include: {
posts: {
select: {
title: true,
},
},
},
})
/*
{
"id": 9
"name": "Sabelle",
"email": "sabelle@prisma.io",
"profileViews": 90,
"role": "USER",
"profile": null,
"coinflips": [],
"posts":[
{
"title":"Getting started with Azure Functions"
},
{
"title":"All about databases"
}
]
}
*/
출처:
https://www.prisma.io/docs/concepts/components/prisma-client/select-fields