sasat 0.19.36 → 0.19.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  export type QueryResponse = Array<{
2
- [key: string]: string;
2
+ [key: string]: SqlValueType;
3
3
  }>;
4
4
  export interface CommandResponse {
5
5
  insertId: number;
@@ -15,18 +15,25 @@ export declare enum QueryNodeKind {
15
15
  Sort = 12,
16
16
  Identifier = 13,
17
17
  Exists = 14,
18
- Raw = 15
18
+ Raw = 15,
19
+ GroupBy = 16
19
20
  }
20
21
  export type LockMode = 'FOR UPDATE' | 'FOR SHARE';
21
22
  export type Query = {
22
23
  select: Select;
23
24
  from: QueryTable;
24
25
  where?: BooleanValueExpression;
26
+ groupBy?: GroupByExpr;
27
+ having?: BooleanValueExpression;
25
28
  sort?: Sort[];
26
29
  limit?: number;
27
30
  offset?: number;
28
31
  lock?: LockMode;
29
32
  };
33
+ export type GroupByExpr = {
34
+ kind: QueryNodeKind.GroupBy;
35
+ cols: (Field | Identifier)[];
36
+ };
30
37
  type Select = SelectExpr[];
31
38
  export declare const NO_ALIAS: "__SASAT_NO_ALIAS";
32
39
  export type Field = {
@@ -16,5 +16,6 @@ export var QueryNodeKind;
16
16
  QueryNodeKind[QueryNodeKind["Identifier"] = 13] = "Identifier";
17
17
  QueryNodeKind[QueryNodeKind["Exists"] = 14] = "Exists";
18
18
  QueryNodeKind[QueryNodeKind["Raw"] = 15] = "Raw";
19
+ QueryNodeKind[QueryNodeKind["GroupBy"] = 16] = "GroupBy";
19
20
  })(QueryNodeKind || (QueryNodeKind = {}));
20
21
  export const NO_ALIAS = '__SASAT_NO_ALIAS';
@@ -13,6 +13,10 @@ export const queryToSql = (query) => {
13
13
  const select = query.select.map(Sql.select).join(', ');
14
14
  const join = getJoin(query.from).map(Sql.join).join(' ');
15
15
  const where = query.where ? ' WHERE ' + Sql.booleanValue(query.where) : '';
16
+ const groupBy = query.groupBy
17
+ ? ' GROUP BY' + query.groupBy.cols.map(Sql.value).join(',')
18
+ : '';
19
+ const having = query.having ? 'HAVING ' + Sql.booleanValue(query.having) : '';
16
20
  const sort = query.sort && query.sort.length !== 0
17
21
  ? ' ORDER BY ' + Sql.sorts(query.sort)
18
22
  : '';
@@ -23,6 +27,8 @@ export const queryToSql = (query) => {
23
27
  return (`SELECT ${select} FROM ${Sql.table(query.from)}` +
24
28
  join +
25
29
  where +
30
+ groupBy +
31
+ having +
26
32
  sort +
27
33
  limit +
28
34
  offset +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.19.36",
3
+ "version": "0.19.37",
4
4
  "repository": "https://github.com/nin138/sasat.git",
5
5
  "author": "nin138 <ninian138@gmail.com>",
6
6
  "license": "MIT",