export interface DynamicQueryStructure { select: string[] | "*"; table: string; where?: Array; join?: Array; orderBy?: { [key: string]: "ASC" | "DESC" }; } export type ConditionStructure = | { type: WhereType; column: string; operation: WhereOperation; value: ConditionValue; } | { type: WhereType; condition: Array; }; export type ConditionValue = FieldType | Array | { start: FieldType; end: FieldType }; export type FieldType = number | string | Date | boolean; export type WhereType = "OR" | "AND" | "_"; export type WhereOperation = | "eq" // Equal | "neq" // Not equal | "lt" // Less than | "lte" // Less than or equal to | "gt" // Greater than | "gte" // Greater than or equal to | "in" // Included in an array | "notIn" // Not included in an array | "contains" // Contains | "notContains" // Does not contain | "null" // Is null | "notNull" // Is not null | "between" // Is between | "startsWith" // Starts with | "endsWith"; // Ends with const exampleQuery: DynamicQueryStructure = { select: ["firstname", "lastname"], table: "member", where: [ { type: "_", column: "mail", operation: "endsWith", value: "@gmail.com", }, { type: "AND", condition: [ { type: "_", column: "firstname", operation: "startsWith", value: "J", }, { type: "OR", column: "lastname", operation: "startsWith", value: "K", }, ], }, ], join: [ { select: "*", table: "communication", foreignColumn: "sendNewsletter", }, ], orderBy: { firstname: "ASC", lastname: "ASC", }, };