builder concept
This commit is contained in:
parent
ee0d6ddcce
commit
63a0a60b12
2 changed files with 217 additions and 11 deletions
|
@ -3,16 +3,18 @@ export interface DynamicQueryStructure {
|
|||
table: string;
|
||||
where?: Array<ConditionStructure>;
|
||||
join?: Array<DynamicQueryStructure & { foreignColumn: string }>;
|
||||
orderBy?: { [key: string]: "ASC" | "DESC" };
|
||||
orderBy?: Array<OrderByStructure>;
|
||||
}
|
||||
|
||||
export type ConditionStructure = (
|
||||
| {
|
||||
structureType: "condition";
|
||||
column: string;
|
||||
operation: WhereOperation;
|
||||
value: ConditionValue;
|
||||
}
|
||||
| {
|
||||
structureType: "nested";
|
||||
invert?: boolean;
|
||||
condition: Array<ConditionStructure>;
|
||||
}
|
||||
|
@ -43,6 +45,13 @@ export type WhereOperation =
|
|||
| "startsWith" // Starts with
|
||||
| "endsWith"; // Ends with
|
||||
|
||||
export type OrderByStructure = {
|
||||
column: string;
|
||||
order: OrderByType;
|
||||
};
|
||||
|
||||
export type OrderByType = "ASC" | "DESC";
|
||||
|
||||
const exampleQuery: DynamicQueryStructure = {
|
||||
select: ["firstname", "lastname"],
|
||||
table: "member",
|
||||
|
@ -103,8 +112,14 @@ const exampleQuery: DynamicQueryStructure = {
|
|||
],
|
||||
},
|
||||
],
|
||||
orderBy: {
|
||||
firstname: "ASC",
|
||||
lastname: "ASC",
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
column: "firstname",
|
||||
order: "ASC",
|
||||
},
|
||||
{
|
||||
column: "lastname",
|
||||
order: "ASC",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue