Daku
Daku
DTDrizzle Team
Created by Daku on 1/3/2025 in #help
Aggregations in a query
const query = await db.query.folders.findMany({
where: queryParams,
columns: {
...folderSelector,
hasFolders: sql<boolean>`EXISTS (SELECT 1 FROM ${folders} WHERE ${folders.parentId} = ${folders.id})`.as('hasFolders'),
},
with: {
creator: userProfileSelector,
organization: organizationUserSelector,
},
});
const query = await db.query.folders.findMany({
where: queryParams,
columns: {
...folderSelector,
hasFolders: sql<boolean>`EXISTS (SELECT 1 FROM ${folders} WHERE ${folders.parentId} = ${folders.id})`.as('hasFolders'),
},
with: {
creator: userProfileSelector,
organization: organizationUserSelector,
},
});
Hello, is there a way to do aggregation within a query.
4 replies