coalesce
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful

This commit is contained in:
jusax23 2023-03-24 21:27:10 +01:00
parent 5d97a3211f
commit 23ebf3c75a
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
2 changed files with 20 additions and 1 deletions

View file

@ -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 = {

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 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);