const aggregations = await prisma.post.aggregate({
_sum: {
likeNum: true
},
_avg: {
likeNum: true
},
_count: {
id: true
},
_max: {
likeNum: true
},
_min: {
likeNum: true
},
})
const groupPosts = await prisma.post.groupBy({
by: ["authorId"],
_sum: {
likeNum: true
},
_avg: {
likeNum: true
},
_count: {
id: true
},
_max: {
likeNum: true
},
_min: {
likeNum: true
},
})
there is update
and updateMany
, both accept ({ where: {}, data: {} })
, also there is an intersting methods to update like upsert
:
const user = await prisma.user.update({
where: { name: 'rush' },
data: {
// increment, decrement, multiply, divide
age: { increment: 1 },
// create or connect or disconnect relations when update
userPrefs: {
create: { emailUpdates: true }
},
userPrefs: {
connect: { id: 114 }
},
userPrefs: {
disconnect: true
}
},
// does'nt accept `select` and `include`
})
const user = await prisma.user.upsert({
where: { name: 'rush' },
update: {
age: { increment: 1 },
userPrefs: {
create: { emailUpdates: true }
},
userPrefs: {
connect: { id: 114 }
},
userPrefs: {
disconnect: true
}
},
create: {
name: "rush",
email: "rush@wusaby.com",
age: 20,
}
})