Compare commits

..

No commits in common. "78d0e9b8a9f6d73eb79bc30eb975c19078c1ee3a" and "f1ed6d095a46ea129b3bc25ce02d92856563b185" have entirely different histories.

2 changed files with 5 additions and 17 deletions

View file

@ -117,16 +117,7 @@ export default abstract class DynamicQueryBuilder {
if (queryObject.join) { if (queryObject.join) {
for (const join of queryObject.join) { for (const join of queryObject.join) {
let subaffix = join.id ?? StringHelper.random(10); let subaffix = join.id ?? StringHelper.random(10);
if (join.type == undefined) join.type = "defined"; query.leftJoin(`${alias}.${join.foreignColumn}`, `${subaffix}_${join.table}`);
if (join.type == "defined") {
query.innerJoin(`${alias}.${join.foreignColumn}`, `${subaffix}_${join.table}`);
} else {
let condition = join.condition
.replaceAll(`${join.table}.`, `${subaffix}_${join.table}.`)
.replaceAll(`${queryObject.table}.`, `${alias}.`);
query.innerJoin(join.table, `${subaffix}_${join.table}`, condition);
}
this.buildDynamicQuery(query, join, subaffix, depth + 1); this.buildDynamicQuery(query, join, subaffix, depth + 1);
} }
@ -138,6 +129,7 @@ export default abstract class DynamicQueryBuilder {
conditions: Array<ConditionStructure>, conditions: Array<ConditionStructure>,
alias: string alias: string
): void { ): void {
console.log(conditions, alias);
for (const condition of conditions) { for (const condition of conditions) {
if (condition.structureType == "condition") { if (condition.structureType == "condition") {
const whereClause = this.buildConditionClause(condition, alias); const whereClause = this.buildConditionClause(condition, alias);
@ -247,6 +239,8 @@ export default abstract class DynamicQueryBuilder {
parameters[`${parameterKey}_end`] = new Date(new Date().getFullYear() - (condition.value as number), 11, 31); parameters[`${parameterKey}_end`] = new Date(new Date().getFullYear() - (condition.value as number), 11, 31);
} }
console.log(query, parameters);
return { query, parameters }; return { query, parameters };
} }
@ -423,7 +417,6 @@ const memberByRunningMembershipQuery: DynamicQueryStructure = {
table: "membership", table: "membership",
where: [{ structureType: "condition", concat: "_", operation: "null", column: "end", value: "" }], where: [{ structureType: "condition", concat: "_", operation: "null", column: "end", value: "" }],
foreignColumn: "memberships", foreignColumn: "memberships",
type: "defined",
}, },
], ],
orderBy: [ orderBy: [

View file

@ -3,7 +3,7 @@ export interface DynamicQueryStructure {
select: string[] | "*"; select: string[] | "*";
table: string; table: string;
where?: Array<ConditionStructure>; where?: Array<ConditionStructure>;
join?: Array<DynamicQueryStructure & JoinStructure>; join?: Array<DynamicQueryStructure & { foreignColumn: string }>;
orderBy?: Array<OrderByStructure>; // only at top level orderBy?: Array<OrderByStructure>; // only at top level
} }
@ -48,8 +48,6 @@ export type WhereOperation =
| "timespanEq"; // Date before x years (YYYY-01-01 <bis> YYYY-12-31) | "timespanEq"; // Date before x years (YYYY-01-01 <bis> YYYY-12-31)
// TODO: age between | age equals | age greater | age smaller // TODO: age between | age equals | age greater | age smaller
export type JoinStructure = { foreignColumn: string; type: "defined" } | { condition: string; type: "custom" };
export type OrderByStructure = { export type OrderByStructure = {
id: string; id: string;
depth: number; depth: number;
@ -103,21 +101,18 @@ export const exampleQuery: DynamicQueryStructure = {
select: "*", select: "*",
table: "communication", table: "communication",
foreignColumn: "sendNewsletter", foreignColumn: "sendNewsletter",
type: "defined",
}, },
{ {
id: "91011", id: "91011",
select: "*", select: "*",
table: "membership", table: "membership",
foreignColumn: "memberships", foreignColumn: "memberships",
type: "defined",
join: [ join: [
{ {
id: "121314", id: "121314",
select: "*", select: "*",
table: "membership_status", table: "membership_status",
foreignColumn: "status", foreignColumn: "status",
type: "defined",
where: [ where: [
{ {
structureType: "condition", structureType: "condition",