Add with=translations in the sql builder logic

This commit is contained in:
Zoe Roux
2025-03-09 01:16:50 +01:00
parent 3f77a1bda5
commit c161d680e3
7 changed files with 104 additions and 11 deletions
+15
View File
@@ -1,6 +1,7 @@
import {
type ColumnsSelection,
type SQL,
type SQLWrapper,
type Subquery,
Table,
View,
@@ -92,3 +93,17 @@ export function values(items: Record<string, unknown>[]) {
},
};
}
export const jsonbObjectAgg = (key: SQLWrapper, value: SQLWrapper) => {
return sql`jsonb_object_agg(${sql.join([key, value], sql.raw(","))})`;
};
export const jsonbBuildObject = (select: Record<string, SQLWrapper>) => {
const query = sql.join(
Object.entries(select).flatMap(([k, v]) => {
return [sql.raw(`'${k}'`), v];
}),
sql.raw(", "),
);
return sql`jsonb_build_object(${query})`;
};