-
Notifications
You must be signed in to change notification settings - Fork 70
/
structured-query.interface.ts
45 lines (43 loc) · 1.15 KB
/
structured-query.interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// The WhereCondition type defines a single condition with a field, operator, and value.
type Operator = 'LIKE' | 'NOT LIKE' | '=' | '<>' | '<' | '>' | '<=' | '>=';
export type WhereCondition = {
field: string;
operator: Operator;
value: string | number;
};
// The WhereClause type allows for both 'and'/'or' groupings and single field conditions.
export type WhereClause = {
and?: (WhereCondition | WhereClause)[];
or?: (WhereCondition | WhereClause)[];
[field: string]:
| WhereCondition
| (WhereCondition | WhereClause)[]
| undefined;
};
// The StructuredQueryInterface includes all parts of an SQL SELECT statement.
export interface StructuredQueryInterface {
select: {
fields: (string | {field: string; alias: string})[];
functions?: {
functionType: 'COUNT' | 'SUM' | 'AVG' | 'MIN' | 'MAX';
field: string;
alias?: string;
}[];
distinct?: boolean;
};
from: {
dataSources: string[];
joins?: {
type: string;
dataSource: string;
on: string;
}[];
};
where?: WhereClause;
orderBy?: {
field: string;
order: 'asc' | 'desc';
}[];
limit?: number;
offset?: number;
}