#5-intelligent-groups #23
1 changed files with 38 additions and 17 deletions
|
@ -1,22 +1,27 @@
|
||||||
export interface DynamicQueryStructure {
|
export interface DynamicQueryStructure {
|
||||||
select: string[] | "*";
|
select: string[] | "*";
|
||||||
table: string;
|
table: string;
|
||||||
where?: Partial<ConditionStructure>;
|
where?: Array<ConditionStructure>;
|
||||||
join?: Array<DynamicQueryStructure & { foreignColumn: string }>;
|
join?: Array<DynamicQueryStructure & { foreignColumn: string }>;
|
||||||
orderBy?: { [key: string]: "ASC" | "DESC" };
|
orderBy?: { [key: string]: "ASC" | "DESC" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConditionStructure = {
|
export type ConditionStructure =
|
||||||
[opt in WhereOptions]: Partial<ConditionStructure> | { [column: string]: Partial<ConditionOperation> };
|
| {
|
||||||
};
|
type: WhereType;
|
||||||
|
column: string;
|
||||||
export type ConditionOperation = {
|
operation: WhereOperation;
|
||||||
[op in WhereOperation]: FieldType | Array<FieldType> | { start: FieldType; end: FieldType };
|
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 FieldType = number | string | Date | boolean;
|
||||||
|
|
||||||
export type WhereOptions = "OR" | "AND";
|
export type WhereType = "OR" | "AND" | "_";
|
||||||
|
|
||||||
export type WhereOperation =
|
export type WhereOperation =
|
||||||
| "eq" // Equal
|
| "eq" // Equal
|
||||||
|
@ -38,15 +43,31 @@ export type WhereOperation =
|
||||||
const exampleQuery: DynamicQueryStructure = {
|
const exampleQuery: DynamicQueryStructure = {
|
||||||
select: ["firstname", "lastname"],
|
select: ["firstname", "lastname"],
|
||||||
table: "member",
|
table: "member",
|
||||||
where: {
|
where: [
|
||||||
AND: {
|
{
|
||||||
mail: { endsWith: "@gmail.com" },
|
type: "_",
|
||||||
OR: {
|
column: "mail",
|
||||||
firstname: { startsWith: "J" },
|
operation: "endsWith",
|
||||||
lastname: { endsWith: "K" },
|
value: "@gmail.com",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "AND",
|
||||||
|
condition: [
|
||||||
|
{
|
||||||
|
type: "_",
|
||||||
|
column: "firstname",
|
||||||
|
operation: "startsWith",
|
||||||
|
value: "J",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "OR",
|
||||||
|
column: "lastname",
|
||||||
|
operation: "startsWith",
|
||||||
|
value: "K",
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
join: [
|
join: [
|
||||||
{
|
{
|
||||||
select: "*",
|
select: "*",
|
||||||
|
|
Loading…
Reference in a new issue