Aggregation with Query API

Hi, is it possible to do aggregation via the query API? I have to do the following at the moment, then I do a form.submissions.length to get the current count. Can it be simplified?
const res = await db.query.formsTbl.findMany({
where: (forms, { eq }) => eq(forms.createdBy, user.userId),
with: {
submissions: {
columns: {
id: true,
},
},
},
})
const res = await db.query.formsTbl.findMany({
where: (forms, { eq }) => eq(forms.createdBy, user.userId),
with: {
submissions: {
columns: {
id: true,
},
},
},
})
Thanks
2 Replies
Mykhailo
Mykhailo11mo ago
Hello, @BiffBaffBoff. As of now aggregations are not supported in relational queries, so you have to use core queries.
Angelelz
Angelelz11mo ago
I would like to add, if form.submissions.length gives you what you want, it will be more performant than doing database aggregations
Want results from more Discord servers?
Add your server