query enhancement

This commit is contained in:
Julian Krauser 2024-11-28 17:53:22 +01:00
parent f05adbd430
commit 74a496a5e0

View file

@ -6,22 +6,25 @@ export interface DynamicQueryStructure {
orderBy?: { [key: string]: "ASC" | "DESC" }; orderBy?: { [key: string]: "ASC" | "DESC" };
} }
export type ConditionStructure = export type ConditionStructure = (
| { | {
type: WhereType;
column: string; column: string;
operation: WhereOperation; operation: WhereOperation;
value: ConditionValue; value: ConditionValue;
} }
| { | {
type: WhereType; invert?: boolean;
condition: Array<ConditionStructure>; condition: Array<ConditionStructure>;
}; }
) & {
concat: WhereType;
structureType: "condition" | "nested";
};
export type ConditionValue = FieldType | Array<FieldType> | { start: FieldType; end: FieldType }; export type ConditionValue = FieldType | Array<FieldType> | { start: FieldType; end: FieldType };
export type FieldType = number | string | Date | boolean; export type FieldType = number | string | Date | boolean;
export type WhereType = "OR" | "AND" | "_"; export type WhereType = "OR" | "AND" | "_"; // _ represents initial where in (sub-)query
export type WhereOperation = export type WhereOperation =
| "eq" // Equal | "eq" // Equal
@ -45,22 +48,26 @@ const exampleQuery: DynamicQueryStructure = {
table: "member", table: "member",
where: [ where: [
{ {
type: "_", structureType: "condition",
concat: "_",
column: "mail", column: "mail",
operation: "endsWith", operation: "endsWith",
value: "@gmail.com", value: "@gmail.com",
}, },
{ {
type: "AND", structureType: "nested",
concat: "AND",
condition: [ condition: [
{ {
type: "_", structureType: "condition",
concat: "_",
column: "firstname", column: "firstname",
operation: "startsWith", operation: "startsWith",
value: "J", value: "J",
}, },
{ {
type: "OR", structureType: "condition",
concat: "OR",
column: "lastname", column: "lastname",
operation: "startsWith", operation: "startsWith",
value: "K", value: "K",
@ -74,6 +81,27 @@ const exampleQuery: DynamicQueryStructure = {
table: "communication", table: "communication",
foreignColumn: "sendNewsletter", foreignColumn: "sendNewsletter",
}, },
{
select: "*",
table: "membership",
foreignColumn: "memberships",
join: [
{
select: "*",
table: "membership_status",
foreignColumn: "status",
where: [
{
structureType: "condition",
concat: "_",
column: "status",
operation: "eq",
value: "aktiv",
},
],
},
],
},
], ],
orderBy: { orderBy: {
firstname: "ASC", firstname: "ASC",