rewrite with db.query

hello there... how can i write it with db.query, as this is chatgpt generated code and it gives me desired results but i want to write it with db.query
export const getPublicNavbarCategories = () => {
return db
.select({
menuItem: getTableColumns(menuItemTable),
categories: sql<Category[]>`
COALESCE(
json_agg(
category.*
) FILTER (WHERE category.id IS NOT NULL),
'[]'
)
`.as('categories'),
})
.from(menuItemTable)
.rightJoin(
categoryTable,
eq(categoryTable.menuItemId, menuItemTable.id),
)
.groupBy(menuItemTable.id)
.orderBy(sql`menu_item."id" IS NULL`, desc(menuItemTable.id));
};
export const getPublicNavbarCategories = () => {
return db
.select({
menuItem: getTableColumns(menuItemTable),
categories: sql<Category[]>`
COALESCE(
json_agg(
category.*
) FILTER (WHERE category.id IS NOT NULL),
'[]'
)
`.as('categories'),
})
.from(menuItemTable)
.rightJoin(
categoryTable,
eq(categoryTable.menuItemId, menuItemTable.id),
)
.groupBy(menuItemTable.id)
.orderBy(sql`menu_item."id" IS NULL`, desc(menuItemTable.id));
};
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?