#5-intelligent-groups #23
1 changed files with 37 additions and 9 deletions
|
@ -6,22 +6,25 @@ export interface DynamicQueryStructure {
|
|||
orderBy?: { [key: string]: "ASC" | "DESC" };
|
||||
}
|
||||
|
||||
export type ConditionStructure =
|
||||
export type ConditionStructure = (
|
||||
| {
|
||||
type: WhereType;
|
||||
column: string;
|
||||
operation: WhereOperation;
|
||||
value: ConditionValue;
|
||||
}
|
||||
| {
|
||||
type: WhereType;
|
||||
invert?: boolean;
|
||||
condition: Array<ConditionStructure>;
|
||||
}
|
||||
) & {
|
||||
concat: WhereType;
|
||||
structureType: "condition" | "nested";
|
||||
};
|
||||
|
||||
export type ConditionValue = FieldType | Array<FieldType> | { start: FieldType; end: FieldType };
|
||||
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 =
|
||||
| "eq" // Equal
|
||||
|
@ -45,22 +48,26 @@ const exampleQuery: DynamicQueryStructure = {
|
|||
table: "member",
|
||||
where: [
|
||||
{
|
||||
type: "_",
|
||||
structureType: "condition",
|
||||
concat: "_",
|
||||
column: "mail",
|
||||
operation: "endsWith",
|
||||
value: "@gmail.com",
|
||||
},
|
||||
{
|
||||
type: "AND",
|
||||
structureType: "nested",
|
||||
concat: "AND",
|
||||
condition: [
|
||||
{
|
||||
type: "_",
|
||||
structureType: "condition",
|
||||
concat: "_",
|
||||
column: "firstname",
|
||||
operation: "startsWith",
|
||||
value: "J",
|
||||
},
|
||||
{
|
||||
type: "OR",
|
||||
structureType: "condition",
|
||||
concat: "OR",
|
||||
column: "lastname",
|
||||
operation: "startsWith",
|
||||
value: "K",
|
||||
|
@ -74,6 +81,27 @@ const exampleQuery: DynamicQueryStructure = {
|
|||
table: "communication",
|
||||
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: {
|
||||
firstname: "ASC",
|
||||
|
|
Loading…
Reference in a new issue