Skip to content

Commit

Permalink
add jsonb_func
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Oct 12, 2023
1 parent 134105f commit 30206f5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
16 changes: 14 additions & 2 deletions lib/DboBuilder/QueryBuilder/Functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1030,14 +1030,26 @@ export const FUNCTIONS: FunctionSpec[] = [
numArgs: 1,
singleColArg: true,
getFields: (args: any[]) => [args[0]],
getQuery: ({ allowedFields, args, tableAlias }) => {
getQuery: ({ args, tableAlias }) => {
let extraArgs = "";
if(args.length > 1){
extraArgs = pgp.as.format(", $1:csv", args.slice(1))
}
return aggName + "(" + asNameAlias(args[0], tableAlias) + `${extraArgs})`;
}
} as FunctionSpec)),
} satisfies FunctionSpec)),

{
name: "$jsonb_build_object",
type: "function",
numArgs: 22,
minCols: 1,
singleColArg: false,
getFields: args => args,
getQuery: ({ args, tableAlias }) => {
return `jsonb_build_object(${args.flatMap(arg => [asName(arg), asNameAlias(arg, tableAlias)]).join(", ")})`;
}
},

/* More aggs */
{
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.1.81",
"version": "4.1.82",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/client/PID.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1507362
1731742
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 30206f5

Please sign in to comment.