From f05adbd430d1fbfe54c6216a4c648a38346ffe8b Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Thu, 28 Nov 2024 14:16:44 +0100 Subject: [PATCH] query build update --- src/type/dynamicQueries.ts | 55 ++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/type/dynamicQueries.ts b/src/type/dynamicQueries.ts index a8c78a9..25abe12 100644 --- a/src/type/dynamicQueries.ts +++ b/src/type/dynamicQueries.ts @@ -1,22 +1,27 @@ export interface DynamicQueryStructure { select: string[] | "*"; table: string; - where?: Partial; + where?: Array; join?: Array; orderBy?: { [key: string]: "ASC" | "DESC" }; } -export type ConditionStructure = { - [opt in WhereOptions]: Partial | { [column: string]: Partial }; -}; - -export type ConditionOperation = { - [op in WhereOperation]: FieldType | Array | { start: FieldType; end: FieldType }; -}; +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 WhereOptions = "OR" | "AND"; +export type WhereType = "OR" | "AND" | "_"; export type WhereOperation = | "eq" // Equal @@ -38,15 +43,31 @@ export type WhereOperation = const exampleQuery: DynamicQueryStructure = { select: ["firstname", "lastname"], table: "member", - where: { - AND: { - mail: { endsWith: "@gmail.com" }, - OR: { - firstname: { startsWith: "J" }, - lastname: { endsWith: "K" }, - }, + 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: "*",