Skip to content

Commit c3caff9

Browse files
author
Greg
committed
add $contains, $contained_by, and $overlap operators
1 parent de4a1c3 commit c3caff9

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,66 @@ Through the REST API:
228228
/messages?text[$ilike]=hello%
229229
```
230230

231+
### $contains
232+
233+
For PostgreSQL only, for array-type fields, finds records that contain _all_ of the given values. The following query retrieves all messages whose labels contain all of the values `important`, `work`, or `urgent` :
234+
235+
```js
236+
app.service('messages').find({
237+
query: {
238+
labels: {
239+
$contains: ['important', 'work', 'urgent']
240+
}
241+
}
242+
});
243+
```
244+
245+
Through the REST API:
246+
247+
```
248+
/messages?label[$contains][0]=important&label[$contains][1]=work&label[$contains][2]=urgent
249+
```
250+
251+
### $contained_by
252+
253+
For PostgreSQL only, for array-type fields, finds records that are contained by the given list of values, i.e do not contain values other than those given. The following query retrieves all messages whose labels contain any of the values `important`, `work`, or `urgent`, but no values outside that list :
254+
255+
```js
256+
app.service('messages').find({
257+
query: {
258+
labels: {
259+
$contained_by: ['important', 'work', 'urgent']
260+
}
261+
}
262+
});
263+
```
264+
265+
Through the REST API:
266+
267+
```
268+
/messages?label[$contained_by][0]=important&label[$contained_by][1]=work&label[$contained_by][2]=urgent
269+
```
270+
271+
### $overlap
272+
273+
For PostgreSQL only, for array-type fields, finds records that overlap (have points in common) with the given values. The following query retrieves all messages whose labels contain one or more of the values `important`, `work`, or `urgent` :
274+
275+
```js
276+
app.service('messages').find({
277+
query: {
278+
labels: {
279+
$overlap: ['important', 'work', 'urgent']
280+
}
281+
}
282+
});
283+
```
284+
285+
Through the REST API:
286+
287+
```
288+
/messages?label[$overlap][0]=important&label[$overlap][1]=work&label[$overlap][2]=urgent
289+
```
290+
231291

232292
## Transaction Support
233293

lib/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ const OPERATORS = {
2323
$gte: '>=',
2424
$like: 'like',
2525
$notlike: 'not like',
26-
$ilike: 'ilike'
26+
$ilike: 'ilike',
27+
$overlap: '&&',
28+
$contains: '@>',
29+
$contained_by: '<@'
2730
};
2831

2932
// Create the service.
@@ -42,8 +45,8 @@ class Service extends AdapterService {
4245
super(Object.assign({
4346
id: 'id'
4447
}, options, {
45-
whitelist: whitelist.concat(['$like', '$notlike', '$ilike', '$and'])
46-
}));
48+
whitelist: whitelist.concat(['$like', '$notlike', '$ilike', '$and', '$overlap', '$contains', '$contained_by'])
49+
}));
4750

4851
this.table = options.name;
4952
this.schema = options.schema;

0 commit comments

Comments
 (0)