From 23ebf3c75a790009985d228950dafd6ee765ba1e Mon Sep 17 00:00:00 2001 From: jusax23 Date: Fri, 24 Mar 2023 21:27:10 +0100 Subject: [PATCH] coalesce --- src/defaultHandler.ts | 20 +++++++++++++++++++- src/funcs.ts | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/defaultHandler.ts b/src/defaultHandler.ts index fce041a..6eb9455 100644 --- a/src/defaultHandler.ts +++ b/src/defaultHandler.ts @@ -825,7 +825,25 @@ export class Handler { } builder.addCode(")"); return builder; - } + }, + coalesce: (handler: Handler, a: allModifierInput[]): QueryBuilder => { + const builder = new QueryBuilder(); + builder.addCode("COALESCE("); + for (let i = 0; i < a.length; i++) { + const e = a[i]; + if (e instanceof Attribute || e instanceof AttributeAlias) builder.addCode(e.getString()); + else if (e instanceof Alias) + builder.addCode(handler.builders.escapeID(e.toString())); + else if (e instanceof Modifier || e instanceof selectQuery || e instanceof Aggregation) { + builder.append(e.serialize(handler)); + } else { + builder.addInjection(e); + } + if (i < a.length - 1) builder.addCode(", "); + } + builder.addCode(")"); + return builder; + }, } datatypes = { diff --git a/src/funcs.ts b/src/funcs.ts index 2c8703c..c3138f3 100644 --- a/src/funcs.ts +++ b/src/funcs.ts @@ -24,6 +24,7 @@ export const regexp = (a: allModifierInput, b: allModifierInput) => new BooleanM export const exists = (q: selectQuery) => new BooleanModifier("exists", [q]); export const concat = (...args: allModifierInput[]) => new StringModifier("concat", args); +export const coalesce = (...args: allModifierInput[]) => new StringModifier("coalesce", args); //aggregations export const count = (a: Attribute) => new Aggregation("count", a);