soul-cli 0.10.0 → 0.11.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/.github/workflows/ci.yml +2 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +12 -0
- package/ROADMAP.md +83 -25
- package/docs/api/rows-examples.md +10 -2
- package/package.json +1 -1
- package/src/controllers/rows.js +115 -92
- package/src/controllers/rows.query.test.js +369 -0
- package/src/schemas/rows.js +4 -1
- package/src/services/rowService.js +12 -6
- package/src/services/rowService.test.js +37 -0
- package/src/swagger/swagger.json +20 -2
- package/src/utils/query.js +285 -0
- package/src/utils/query.test.js +147 -0
- package/src/utils/sql.js +24 -0
- package/src/utils/sql.test.js +14 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
const supertest = require('supertest');
|
|
2
|
+
|
|
3
|
+
const app = require('../index');
|
|
4
|
+
const db = require('../db/index');
|
|
5
|
+
const config = require('../config');
|
|
6
|
+
const { generateToken } = require('../utils');
|
|
7
|
+
|
|
8
|
+
const requestWithSupertest = supertest(app);
|
|
9
|
+
|
|
10
|
+
describe('Rows query params', () => {
|
|
11
|
+
let accessToken;
|
|
12
|
+
|
|
13
|
+
const get = (query) =>
|
|
14
|
+
requestWithSupertest
|
|
15
|
+
.get(`/api/tables/qtest/rows?${query}`)
|
|
16
|
+
.set('Cookie', [`accessToken=${accessToken}`]);
|
|
17
|
+
|
|
18
|
+
const filter = (filters, extra = '') =>
|
|
19
|
+
get(`_filters=${encodeURIComponent(filters)}&_ordering=id${extra}`);
|
|
20
|
+
|
|
21
|
+
const names = (res) => res.body.data.map((row) => row.name);
|
|
22
|
+
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
accessToken = await generateToken(
|
|
25
|
+
{ username: 'John', isSuperuser: true },
|
|
26
|
+
config.tokenSecret,
|
|
27
|
+
'1H',
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
db.prepare(
|
|
31
|
+
'CREATE TABLE qtest (id INTEGER PRIMARY KEY, name TEXT, category TEXT, price INTEGER, note TEXT)',
|
|
32
|
+
).run();
|
|
33
|
+
const insert = db.prepare(
|
|
34
|
+
'INSERT INTO qtest (name, category, price, note) VALUES (?, ?, ?, ?)',
|
|
35
|
+
);
|
|
36
|
+
[
|
|
37
|
+
['Apple', 'fruit', 3, null],
|
|
38
|
+
['Banana', 'fruit', 5, 'a,b'],
|
|
39
|
+
['Carrot', 'veg', 2, 'x:y'],
|
|
40
|
+
['Date', 'fruit', 5, 'p|q'],
|
|
41
|
+
['Eggplant', 'veg', 7, '(raw)'],
|
|
42
|
+
['Fig', 'fruit', 9, ''],
|
|
43
|
+
['Grape', 'fruit', 4, '100%'],
|
|
44
|
+
].forEach((row) => insert.run(...row));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterAll(() => {
|
|
48
|
+
db.prepare('DROP TABLE IF EXISTS qtest').run();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('existing _filters behavior', () => {
|
|
52
|
+
it('ANDs comma-separated filters', async () => {
|
|
53
|
+
const res = await filter('category:fruit,price__gte:5');
|
|
54
|
+
expect(names(res)).toEqual(['Banana', 'Date', 'Fig']);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('turns a bracketed value into IN for any operator', async () => {
|
|
58
|
+
const res = await filter('id__neq:[1,2]');
|
|
59
|
+
expect(res.body.data.map((row) => row.id)).toEqual([1, 2]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('keeps colons inside a value', async () => {
|
|
63
|
+
const res = await filter('note:x:y');
|
|
64
|
+
expect(names(res)).toEqual(['Carrot']);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('returns 400 for an empty value', async () => {
|
|
68
|
+
const res = await filter('note:');
|
|
69
|
+
expect(res.status).toEqual(400);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('returns 400 for an unknown operator and lists the valid ones', async () => {
|
|
73
|
+
const res = await filter('price__bogus:1');
|
|
74
|
+
expect(res.status).toEqual(400);
|
|
75
|
+
expect(res.body.message).toContain('__between');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('filters null values', async () => {
|
|
79
|
+
const res = await filter('note__null');
|
|
80
|
+
expect(names(res)).toEqual(['Apple']);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('_ordering', () => {
|
|
85
|
+
it('orders by several columns', async () => {
|
|
86
|
+
const res = await get('_ordering=category,-price,name');
|
|
87
|
+
expect(names(res)).toEqual([
|
|
88
|
+
'Fig',
|
|
89
|
+
'Banana',
|
|
90
|
+
'Date',
|
|
91
|
+
'Grape',
|
|
92
|
+
'Apple',
|
|
93
|
+
'Eggplant',
|
|
94
|
+
'Carrot',
|
|
95
|
+
]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('returns 400 when one of the columns does not exist', async () => {
|
|
99
|
+
const res = await get('_ordering=category,bogus');
|
|
100
|
+
expect(res.status).toEqual(400);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('joins a related table once when ordering by it twice', async () => {
|
|
104
|
+
const res = await requestWithSupertest
|
|
105
|
+
.get(
|
|
106
|
+
'/api/tables/posts/rows?_ordering=userId.firstName,-userId.lastName&_extend=userId',
|
|
107
|
+
)
|
|
108
|
+
.set('Cookie', [`accessToken=${accessToken}`]);
|
|
109
|
+
expect(res.status).toEqual(200);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('_distinct', () => {
|
|
114
|
+
it('returns unique values and a matching total', async () => {
|
|
115
|
+
const res = await get('_distinct=category&_ordering=category&_limit=1');
|
|
116
|
+
expect(res.status).toEqual(200);
|
|
117
|
+
expect(res.body.data).toEqual([{ category: 'fruit' }]);
|
|
118
|
+
expect(res.body.total).toEqual(2);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('returns unique combinations of several columns', async () => {
|
|
122
|
+
const res = await get(
|
|
123
|
+
'_distinct=category,price&_ordering=category,price',
|
|
124
|
+
);
|
|
125
|
+
expect(res.body.data).toHaveLength(6);
|
|
126
|
+
expect(res.body.total).toEqual(6);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('returns 400 for an unknown column', async () => {
|
|
130
|
+
const res = await get('_distinct=bogus');
|
|
131
|
+
expect(res.status).toEqual(400);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('returns 400 when combined with _schema', async () => {
|
|
135
|
+
const res = await get('_distinct=category&_schema=name');
|
|
136
|
+
expect(res.status).toEqual(400);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('returns 400 when combined with _group_by', async () => {
|
|
140
|
+
const res = await get('_distinct=category&_group_by=category');
|
|
141
|
+
expect(res.status).toEqual(400);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('operators', () => {
|
|
146
|
+
it('like uses the given pattern', async () => {
|
|
147
|
+
const res = await filter('name__like:A%');
|
|
148
|
+
expect(names(res)).toEqual(['Apple']);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('contains matches anywhere', async () => {
|
|
152
|
+
const res = await filter('name__contains:an');
|
|
153
|
+
expect(names(res)).toEqual(['Banana', 'Eggplant']);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('startswith matches the beginning', async () => {
|
|
157
|
+
const res = await filter('name__startswith:E');
|
|
158
|
+
expect(names(res)).toEqual(['Eggplant']);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('contains treats % and _ literally', async () => {
|
|
162
|
+
expect(names(await filter('note__contains:%'))).toEqual(['Grape']);
|
|
163
|
+
expect(names(await filter('note__contains:_'))).toEqual([]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('between is inclusive', async () => {
|
|
167
|
+
const res = await filter('price__between:[3,5]');
|
|
168
|
+
expect(names(res)).toEqual(['Apple', 'Banana', 'Date', 'Grape']);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('between needs exactly two values', async () => {
|
|
172
|
+
expect((await filter('price__between:5')).status).toEqual(400);
|
|
173
|
+
expect((await filter('price__between:[1,2,3]')).status).toEqual(400);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('in and notin take a list or a single value', async () => {
|
|
177
|
+
expect(names(await filter('id__in:[1,2]'))).toEqual(['Apple', 'Banana']);
|
|
178
|
+
expect(names(await filter('id__in:3'))).toEqual(['Carrot']);
|
|
179
|
+
expect(names(await filter('id__notin:[1,2,3,4,5,6]'))).toEqual(['Grape']);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('like operators reject a list', async () => {
|
|
183
|
+
const res = await filter('name__like:[a,b]');
|
|
184
|
+
expect(res.status).toEqual(400);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('quoted values', () => {
|
|
189
|
+
it('allows commas, colons and pipes inside quotes', async () => {
|
|
190
|
+
expect(names(await filter('note:"a,b"'))).toEqual(['Banana']);
|
|
191
|
+
expect(names(await filter('note:"x:y"'))).toEqual(['Carrot']);
|
|
192
|
+
expect(names(await filter('note:"p|q"'))).toEqual(['Date']);
|
|
193
|
+
expect(names(await filter('note:"(raw)"'))).toEqual(['Eggplant']);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('allows quoted values inside a list and next to other filters', async () => {
|
|
197
|
+
expect(names(await filter('note:["a,b","x:y"]'))).toEqual([
|
|
198
|
+
'Banana',
|
|
199
|
+
'Carrot',
|
|
200
|
+
]);
|
|
201
|
+
expect(names(await filter('note:"a,b",category:fruit'))).toEqual([
|
|
202
|
+
'Banana',
|
|
203
|
+
]);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('matches an empty string with ""', async () => {
|
|
207
|
+
expect(names(await filter('note:""'))).toEqual(['Fig']);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('treats an unclosed or trailing-text quote literally', async () => {
|
|
211
|
+
const unclosed = await filter('name:"Apple');
|
|
212
|
+
expect(unclosed.status).toEqual(200);
|
|
213
|
+
expect(unclosed.body.data).toEqual([]);
|
|
214
|
+
expect((await filter('name:"Apple"x')).body.data).toEqual([]);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('OR groups and NOT', () => {
|
|
219
|
+
it('ORs the filters inside a group', async () => {
|
|
220
|
+
const res = await filter('(category:veg|price__gte:9)');
|
|
221
|
+
expect(names(res)).toEqual(['Carrot', 'Eggplant', 'Fig']);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('ANDs a group with other filters', async () => {
|
|
225
|
+
const res = await filter('(category:veg|price__gte:9),price__lt:8');
|
|
226
|
+
expect(names(res)).toEqual(['Carrot', 'Eggplant']);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('protects | inside quoted values', async () => {
|
|
230
|
+
const res = await filter('(note:"p|q"|note:"a,b")');
|
|
231
|
+
expect(names(res)).toEqual(['Banana', 'Date']);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('negates a filter with !', async () => {
|
|
235
|
+
const res = await filter('!category:veg');
|
|
236
|
+
expect(names(res)).toEqual(['Apple', 'Banana', 'Date', 'Fig', 'Grape']);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('negates a group with !', async () => {
|
|
240
|
+
const res = await filter('!(category:veg|price__gte:9)');
|
|
241
|
+
expect(names(res)).toEqual(['Apple', 'Banana', 'Date', 'Grape']);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('negates inside a group', async () => {
|
|
245
|
+
const res = await filter('(!category:fruit|id:1)');
|
|
246
|
+
expect(names(res)).toEqual(['Apple', 'Carrot', 'Eggplant']);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('excludes NULL rows when negating, like __neq', async () => {
|
|
250
|
+
const res = await filter('!note:x:y');
|
|
251
|
+
expect(names(res)).toEqual([
|
|
252
|
+
'Banana',
|
|
253
|
+
'Date',
|
|
254
|
+
'Eggplant',
|
|
255
|
+
'Fig',
|
|
256
|
+
'Grape',
|
|
257
|
+
]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('returns 400 for an unclosed group', async () => {
|
|
261
|
+
expect((await filter('(category:veg')).status).toEqual(400);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('returns 400 for a comma inside a group', async () => {
|
|
265
|
+
expect((await filter('(category:veg,price:2)')).status).toEqual(400);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('returns 400 for an unknown column inside a group', async () => {
|
|
269
|
+
expect((await filter('(bogus:1|id:2)')).status).toEqual(400);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe('_group_by and _aggregate', () => {
|
|
274
|
+
it('groups rows and aggregates them', async () => {
|
|
275
|
+
const res = await get(
|
|
276
|
+
'_group_by=category&_aggregate=count,sum:price,avg:price,min:price,max:price&_ordering=category',
|
|
277
|
+
);
|
|
278
|
+
expect(res.status).toEqual(200);
|
|
279
|
+
expect(res.body.data).toEqual([
|
|
280
|
+
{
|
|
281
|
+
category: 'fruit',
|
|
282
|
+
count: 5,
|
|
283
|
+
sum_price: 26,
|
|
284
|
+
avg_price: 5.2,
|
|
285
|
+
min_price: 3,
|
|
286
|
+
max_price: 9,
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
category: 'veg',
|
|
290
|
+
count: 2,
|
|
291
|
+
sum_price: 9,
|
|
292
|
+
avg_price: 4.5,
|
|
293
|
+
min_price: 2,
|
|
294
|
+
max_price: 7,
|
|
295
|
+
},
|
|
296
|
+
]);
|
|
297
|
+
expect(res.body.total).toEqual(2);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('orders by an aggregate alias', async () => {
|
|
301
|
+
const res = await get(
|
|
302
|
+
'_group_by=category&_aggregate=sum:price&_ordering=-sum_price',
|
|
303
|
+
);
|
|
304
|
+
expect(res.body.data.map((row) => row.category)).toEqual([
|
|
305
|
+
'fruit',
|
|
306
|
+
'veg',
|
|
307
|
+
]);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('returns a single row when only _aggregate is given', async () => {
|
|
311
|
+
const res = await get('_aggregate=count');
|
|
312
|
+
expect(res.body.data).toEqual([{ count: 7 }]);
|
|
313
|
+
expect(res.body.total).toEqual(1);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('supports count:column', async () => {
|
|
317
|
+
const res = await get('_aggregate=count:note');
|
|
318
|
+
expect(res.body.data).toEqual([{ count_note: 6 }]);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('applies _filters before grouping', async () => {
|
|
322
|
+
const res = await get(
|
|
323
|
+
'_filters=category:fruit&_group_by=category&_aggregate=count',
|
|
324
|
+
);
|
|
325
|
+
expect(res.body.data).toEqual([{ category: 'fruit', count: 5 }]);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('groups without an aggregate', async () => {
|
|
329
|
+
const res = await get('_group_by=category&_ordering=category');
|
|
330
|
+
expect(res.body.data).toEqual([
|
|
331
|
+
{ category: 'fruit' },
|
|
332
|
+
{ category: 'veg' },
|
|
333
|
+
]);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('keeps total and pagination links correct', async () => {
|
|
337
|
+
const res = await get('_group_by=price&_ordering=price&_limit=2');
|
|
338
|
+
expect(res.body.data).toHaveLength(2);
|
|
339
|
+
expect(res.body.total).toEqual(6);
|
|
340
|
+
expect(res.body.next).toContain('_group_by=price');
|
|
341
|
+
expect(res.body.previous).toBeNull();
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('returns 400 for bad input', async () => {
|
|
345
|
+
const bad = [
|
|
346
|
+
'_group_by=bogus',
|
|
347
|
+
'_group_by=category&_ordering=name',
|
|
348
|
+
'_group_by=category&_schema=name',
|
|
349
|
+
'_aggregate=median:price',
|
|
350
|
+
'_aggregate=sum',
|
|
351
|
+
'_aggregate=count:bogus',
|
|
352
|
+
'_aggregate=sum:price:x',
|
|
353
|
+
`_aggregate=${encodeURIComponent('count:price) FROM qtest --')}`,
|
|
354
|
+
];
|
|
355
|
+
for (const query of bad) {
|
|
356
|
+
const res = await get(query);
|
|
357
|
+
expect([query, res.status]).toEqual([query, 400]);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('does not run injected SQL in _group_by', async () => {
|
|
362
|
+
const res = await get(
|
|
363
|
+
`_group_by=${encodeURIComponent('category;DROP TABLE qtest')}`,
|
|
364
|
+
);
|
|
365
|
+
expect(res.status).toEqual(400);
|
|
366
|
+
expect((await get('_limit=1')).status).toEqual(200);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
});
|
package/src/schemas/rows.js
CHANGED
|
@@ -5,10 +5,13 @@ const listTableRows = Joi.object({
|
|
|
5
5
|
_page: Joi.number().integer().min(1).default(1),
|
|
6
6
|
_limit: Joi.number().integer().min(1).default(10),
|
|
7
7
|
_search: Joi.string(),
|
|
8
|
-
_ordering: Joi.string().regex(/^[\w
|
|
8
|
+
_ordering: Joi.string().regex(/^[\w.,-]+$/),
|
|
9
9
|
_schema: Joi.string(),
|
|
10
10
|
_extend: Joi.string(),
|
|
11
11
|
_filters: Joi.string(),
|
|
12
|
+
_distinct: Joi.string(),
|
|
13
|
+
_group_by: Joi.string(),
|
|
14
|
+
_aggregate: Joi.string(),
|
|
12
15
|
}).required(),
|
|
13
16
|
params: Joi.object({
|
|
14
17
|
name: Joi.string(),
|
|
@@ -4,11 +4,11 @@ const { quoteIdentifier } = require('../utils/sql');
|
|
|
4
4
|
module.exports = (db) => {
|
|
5
5
|
return {
|
|
6
6
|
get(data) {
|
|
7
|
-
const query = `SELECT ${data.
|
|
8
|
-
data.
|
|
9
|
-
} ${data.
|
|
10
|
-
data.
|
|
11
|
-
} LIMIT ? OFFSET ?`;
|
|
7
|
+
const query = `SELECT ${data.distinct ? 'DISTINCT ' : ''}${
|
|
8
|
+
data.schemaString || '*'
|
|
9
|
+
} FROM ${data.tableName} ${data.extendString || ''} ${
|
|
10
|
+
data.whereString || ''
|
|
11
|
+
} ${data.groupString || ''} ${data.orderString || ''} LIMIT ? OFFSET ?`;
|
|
12
12
|
|
|
13
13
|
const statement = db.prepare(query);
|
|
14
14
|
const result = statement.all(
|
|
@@ -30,7 +30,13 @@ module.exports = (db) => {
|
|
|
30
30
|
},
|
|
31
31
|
|
|
32
32
|
getCount(data) {
|
|
33
|
-
const
|
|
33
|
+
const from = `FROM ${data.tableName} ${data.whereString}`;
|
|
34
|
+
let query = `SELECT COUNT(*) as total ${from}`;
|
|
35
|
+
if (data.groupString) {
|
|
36
|
+
query = `SELECT COUNT(*) as total FROM (SELECT 1 ${from} ${data.groupString})`;
|
|
37
|
+
} else if (data.distinctString) {
|
|
38
|
+
query = `SELECT COUNT(*) as total FROM (SELECT DISTINCT ${data.distinctString} ${from})`;
|
|
39
|
+
}
|
|
34
40
|
const statement = db.prepare(query);
|
|
35
41
|
const result = statement.get(...data.whereStringValues).total;
|
|
36
42
|
return result;
|
|
@@ -149,5 +149,42 @@ describe('rowService', () => {
|
|
|
149
149
|
});
|
|
150
150
|
expect(total).toBe(2);
|
|
151
151
|
});
|
|
152
|
+
|
|
153
|
+
it('supports distinct, group by and their totals', () => {
|
|
154
|
+
rowService.save({ tableName: 'authors', fields: { name: 'Ada' } });
|
|
155
|
+
rowService.save({ tableName: 'authors', fields: { name: 'Beta' } });
|
|
156
|
+
const base = {
|
|
157
|
+
tableName: 'authors',
|
|
158
|
+
whereString: '',
|
|
159
|
+
whereStringValues: [],
|
|
160
|
+
schemaString: 'authors.name',
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const distinct = rowService.get({ ...base, distinct: true });
|
|
164
|
+
expect(distinct).toHaveLength(2);
|
|
165
|
+
expect(
|
|
166
|
+
rowService.getCount({
|
|
167
|
+
...base,
|
|
168
|
+
distinctString: 'authors.name',
|
|
169
|
+
}),
|
|
170
|
+
).toBe(2);
|
|
171
|
+
|
|
172
|
+
const grouped = rowService.get({
|
|
173
|
+
...base,
|
|
174
|
+
schemaString: 'authors.name, COUNT(*) AS "count"',
|
|
175
|
+
groupString: 'GROUP BY authors.name',
|
|
176
|
+
orderString: ' ORDER BY authors.name ASC',
|
|
177
|
+
});
|
|
178
|
+
expect(grouped).toEqual([
|
|
179
|
+
{ name: 'Ada', count: 2 },
|
|
180
|
+
{ name: 'Beta', count: 1 },
|
|
181
|
+
]);
|
|
182
|
+
expect(
|
|
183
|
+
rowService.getCount({
|
|
184
|
+
...base,
|
|
185
|
+
groupString: 'GROUP BY authors.name',
|
|
186
|
+
}),
|
|
187
|
+
).toBe(2);
|
|
188
|
+
});
|
|
152
189
|
});
|
|
153
190
|
});
|
package/src/swagger/swagger.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"swagger": "2.0",
|
|
3
3
|
"info": {
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"title": "Soul API",
|
|
6
6
|
"description": "API Documentation for <b>Soul</b>, a SQLite REST and realtime server. "
|
|
7
7
|
},
|
|
@@ -237,7 +237,25 @@
|
|
|
237
237
|
},
|
|
238
238
|
{
|
|
239
239
|
"name": "_filters",
|
|
240
|
-
"description": "Filter rows. e.g. ?_filters=name:John,age:20 will return rows where name is John and age is 20.",
|
|
240
|
+
"description": "Filter rows. e.g. ?_filters=name:John,age:20 will return rows where name is John and age is 20. Operators: __eq, __neq, __lt, __gt, __lte, __gte, __null, __notnull, __like, __contains, __startswith, __between, __in, __notin. Lists use brackets, e.g. id:[1,2]. Wrap a value in double quote characters to use , : | in it. (a:1|b:2) is an OR group and ! negates a filter or group.",
|
|
241
|
+
"in": "query",
|
|
242
|
+
"type": "string"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"name": "_distinct",
|
|
246
|
+
"description": "Return unique combinations of these columns. e.g. ?_distinct=category,price",
|
|
247
|
+
"in": "query",
|
|
248
|
+
"type": "string"
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
"name": "_group_by",
|
|
252
|
+
"description": "Group rows by these columns. e.g. ?_group_by=category",
|
|
253
|
+
"in": "query",
|
|
254
|
+
"type": "string"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"name": "_aggregate",
|
|
258
|
+
"description": "Aggregates: count, sum:col, avg:col, min:col, max:col. e.g. ?_group_by=category&_aggregate=count,sum:price. Results are named count, sum_price, ...",
|
|
241
259
|
"in": "query",
|
|
242
260
|
"type": "string"
|
|
243
261
|
},
|