#5-intelligent-groups #23
1 changed files with 38 additions and 17 deletions
|
@ -1,22 +1,27 @@
|
|||
export interface DynamicQueryStructure {
|
||||
select: string[] | "*";
|
||||
table: string;
|
||||
where?: Partial<ConditionStructure>;
|
||||
where?: Array<ConditionStructure>;
|
||||
join?: Array<DynamicQueryStructure & { foreignColumn: string }>;
|
||||
orderBy?: { [key: string]: "ASC" | "DESC" };
|
||||
}
|
||||
|
||||
export type ConditionStructure = {
|
||||
[opt in WhereOptions]: Partial<ConditionStructure> | { [column: string]: Partial<ConditionOperation> };
|
||||
};
|
||||
|
||||
export type ConditionOperation = {
|
||||
[op in WhereOperation]: FieldType | Array<FieldType> | { start: FieldType; end: FieldType };
|
||||
export type ConditionStructure =
|
||||
| {
|
||||
type: WhereType;
|
||||
column: string;
|
||||
operation: WhereOperation;
|
||||
value: ConditionValue;
|
||||
}
|
||||
| {
|
||||
type: WhereType;
|
||||
condition: Array<ConditionStructure>;
|
||||
};
|
||||
|
||||
export type ConditionValue = FieldType | Array<FieldType> | { 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: "*",
|
||||
|
|
Loading…
Reference in a new issue