coalesce #21

Merged
jusax23 merged 1 commit from dev into main 2023-03-24 21:27:50 +01:00
2 changed files with 20 additions and 1 deletions
Showing only changes of commit 23ebf3c75a - Show all commits

View file

@ -825,7 +825,25 @@ export class Handler {
} }
builder.addCode(")"); builder.addCode(")");
return builder; 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 = { datatypes = {

View file

@ -24,6 +24,7 @@ export const regexp = (a: allModifierInput, b: allModifierInput) => new BooleanM
export const exists = (q: selectQuery) => new BooleanModifier("exists", [q]); export const exists = (q: selectQuery) => new BooleanModifier("exists", [q]);
export const concat = (...args: allModifierInput[]) => new StringModifier("concat", args); export const concat = (...args: allModifierInput[]) => new StringModifier("concat", args);
export const coalesce = (...args: allModifierInput[]) => new StringModifier("coalesce", args);
//aggregations //aggregations
export const count = (a: Attribute) => new Aggregation("count", a); export const count = (a: Attribute) => new Aggregation("count", a);