@naturalcycles/db-lib 8.28.2 → 8.29.0
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.
- package/dist/query/dbQuery.d.ts +2 -0
- package/dist/query/dbQuery.js +7 -0
- package/package.json +1 -1
- package/src/query/dbQuery.ts +10 -0
package/dist/query/dbQuery.d.ts
CHANGED
|
@@ -64,12 +64,14 @@ export declare class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
|
64
64
|
* In undefined - all fields (*) will be returned.
|
|
65
65
|
*/
|
|
66
66
|
_selectedFieldNames?: (keyof ROW)[];
|
|
67
|
+
_groupByFieldNames?: (keyof ROW)[];
|
|
67
68
|
filter(name: keyof ROW, op: DBQueryFilterOperator, val: any): this;
|
|
68
69
|
filterEq(name: keyof ROW, val: any): this;
|
|
69
70
|
limit(limit: number): this;
|
|
70
71
|
offset(offset: number): this;
|
|
71
72
|
order(name: keyof ROW, descending?: boolean): this;
|
|
72
73
|
select(fieldNames: (keyof ROW)[]): this;
|
|
74
|
+
groupBy(fieldNames: (keyof ROW)[]): this;
|
|
73
75
|
startCursor(startCursor?: string): this;
|
|
74
76
|
endCursor(endCursor?: string): this;
|
|
75
77
|
clone(): DBQuery<ROW>;
|
package/dist/query/dbQuery.js
CHANGED
|
@@ -67,6 +67,10 @@ class DBQuery {
|
|
|
67
67
|
this._selectedFieldNames = fieldNames;
|
|
68
68
|
return this;
|
|
69
69
|
}
|
|
70
|
+
groupBy(fieldNames) {
|
|
71
|
+
this._groupByFieldNames = fieldNames;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
70
74
|
startCursor(startCursor) {
|
|
71
75
|
this._startCursor = startCursor;
|
|
72
76
|
return this;
|
|
@@ -98,6 +102,9 @@ class DBQuery {
|
|
|
98
102
|
tokens.push(`select(${this._selectedFieldNames.join(',')})`);
|
|
99
103
|
}
|
|
100
104
|
tokens.push(...this._filters.map(f => `${f.name}${f.op}${f.val}`), ...this._orders.map(o => `order by ${o.name}${o.descending ? ' desc' : ''}`));
|
|
105
|
+
if (this._groupByFieldNames) {
|
|
106
|
+
tokens.push(`groupBy(${this._groupByFieldNames.join(',')})`);
|
|
107
|
+
}
|
|
101
108
|
if (this._offsetValue) {
|
|
102
109
|
tokens.push(`offset ${this._offsetValue}`);
|
|
103
110
|
}
|
package/package.json
CHANGED
package/src/query/dbQuery.ts
CHANGED
|
@@ -96,6 +96,7 @@ export class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
|
96
96
|
* In undefined - all fields (*) will be returned.
|
|
97
97
|
*/
|
|
98
98
|
_selectedFieldNames?: (keyof ROW)[]
|
|
99
|
+
_groupByFieldNames?: (keyof ROW)[]
|
|
99
100
|
|
|
100
101
|
filter(name: keyof ROW, op: DBQueryFilterOperator, val: any): this {
|
|
101
102
|
this._filters.push({ name, op, val })
|
|
@@ -130,6 +131,11 @@ export class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
|
130
131
|
return this
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
groupBy(fieldNames: (keyof ROW)[]): this {
|
|
135
|
+
this._groupByFieldNames = fieldNames
|
|
136
|
+
return this
|
|
137
|
+
}
|
|
138
|
+
|
|
133
139
|
startCursor(startCursor?: string): this {
|
|
134
140
|
this._startCursor = startCursor
|
|
135
141
|
return this
|
|
@@ -172,6 +178,10 @@ export class DBQuery<ROW extends ObjectWithId = AnyObjectWithId> {
|
|
|
172
178
|
...this._orders.map(o => `order by ${o.name}${o.descending ? ' desc' : ''}`),
|
|
173
179
|
)
|
|
174
180
|
|
|
181
|
+
if (this._groupByFieldNames) {
|
|
182
|
+
tokens.push(`groupBy(${this._groupByFieldNames.join(',')})`)
|
|
183
|
+
}
|
|
184
|
+
|
|
175
185
|
if (this._offsetValue) {
|
|
176
186
|
tokens.push(`offset ${this._offsetValue}`)
|
|
177
187
|
}
|