Skip to content

Commit 191f4bf

Browse files
author
Greg
committed
add $contains, $contained_by, and $overlap operators
1 parent 17ee6da commit 191f4bf

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
@@ -227,6 +227,66 @@ Through the REST API:
227227
/messages?text[$ilike]=hello%
228228
```
229229

230+
### $contains
231+
232+
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` :
233+
234+
```js
235+
app.service('messages').find({
236+
query: {
237+
labels: {
238+
$contains: ['important', 'work', 'urgent']
239+
}
240+
}
241+
});
242+
```
243+
244+
Through the REST API:
245+
246+
```
247+
/messages?label[$contains][0]=important&label[$contains][1]=work&label[$contains][2]=urgent
248+
```
249+
250+
### $contained_by
251+
252+
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 :
253+
254+
```js
255+
app.service('messages').find({
256+
query: {
257+
labels: {
258+
$contained_by: ['important', 'work', 'urgent']
259+
}
260+
}
261+
});
262+
```
263+
264+
Through the REST API:
265+
266+
```
267+
/messages?label[$contained_by][0]=important&label[$contained_by][1]=work&label[$contained_by][2]=urgent
268+
```
269+
270+
### $overlap
271+
272+
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` :
273+
274+
```js
275+
app.service('messages').find({
276+
query: {
277+
labels: {
278+
$overlap: ['important', 'work', 'urgent']
279+
}
280+
}
281+
});
282+
```
283+
284+
Through the REST API:
285+
286+
```
287+
/messages?label[$overlap][0]=important&label[$overlap][1]=work&label[$overlap][2]=urgent
288+
```
289+
230290

231291
## Transaction Support
232292

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)