Skip to content

Commit e4cff49

Browse files
Vladimir UpirovStanislaw
authored andcommitted
feat: (Data) Aggregation Functions (#115)
- BKNDLSS-16033 Add groupBy list and havingClause to BackendlessDataQuery
1 parent 9b9e568 commit e4cff49

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

src/data/query-builder.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ export default class DataQueryBuilder {
6363
return this
6464
}
6565

66+
getHavingClause() {
67+
return this._query.havingClause
68+
}
69+
70+
setHavingClause(havingClause) {
71+
this._query.havingClause = havingClause
72+
73+
return this
74+
}
75+
6676
getSortBy() {
6777
return this._query.getOption('sortBy')
6878
}
@@ -73,6 +83,16 @@ export default class DataQueryBuilder {
7383
return this
7484
}
7585

86+
getGroupBy() {
87+
return this._query.getOption('groupBy')
88+
}
89+
90+
setGroupBy(groupBy) {
91+
this._query.setOption('groupBy', Utils.castArray(groupBy))
92+
93+
return this
94+
}
95+
7696
getRelated() {
7797
return this._query.getOption('relations')
7898
}

src/data/query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default class DataQuery {
44

55
this.properties = args.properties || []
66
this.condition = args.condition || null
7+
this.havingClause = args.havingClause || null
78
this.options = args.options || null
89
this.url = args.url || null
910
}

src/data/store/extract-query-options.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ export function extractQueryOptions(options) {
3131
}
3232
}
3333

34+
if (options.groupBy) {
35+
if (Utils.isString(options.groupBy)) {
36+
params.push('groupBy=' + encodeURIComponent(options.groupBy))
37+
} else if (Utils.isArray(options.groupBy)) {
38+
params.push('groupBy=' + Utils.encodeArrayToUriComponent(options.groupBy))
39+
}
40+
}
41+
3442
if (options.relationsDepth) {
3543
if (Utils.isNumber(options.relationsDepth)) {
3644
params.push('relationsDepth=' + Math.floor(options.relationsDepth))

src/data/store/find.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export function findUtil(className, Model, dataQuery, asyncHandler) {
2828
query.push('where=' + encodeURIComponent(dataQuery.condition))
2929
}
3030

31+
if (dataQuery.havingClause) {
32+
query.push('having=' + encodeURIComponent(dataQuery.havingClause))
33+
}
34+
3135
if (dataQuery.properties && dataQuery.properties.length) {
3236
query.push('props=' + Utils.encodeArrayToUriComponent(dataQuery.properties))
3337
}

src/data/store/relations.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ export function loadRelations(parentObjectId, queryBuilder, asyncHandler) {
110110
query.push('where=' + encodeURIComponent(dataQuery.condition))
111111
}
112112

113+
if (dataQuery.havingClause) {
114+
query.push('having=' + encodeURIComponent(dataQuery.havingClause))
115+
}
116+
113117
let url = Urls.dataTableObjectRelation(this.className, parentObjectId, relationName)
114118

115119
if (asyncHandler) {

0 commit comments

Comments
 (0)