diff --git a/README.md b/README.md index e96c684..a86c0de 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,66 @@ Through the REST API: /messages?text[$ilike]=hello% ``` +### $contains + +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` : + +```js +app.service('messages').find({ + query: { + labels: { + $contains: ['important', 'work', 'urgent'] + } + } +}); +``` + +Through the REST API: + +``` +/messages?label[$contains][0]=important&label[$contains][1]=work&label[$contains][2]=urgent +``` + +### $contained_by + +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 : + +```js +app.service('messages').find({ + query: { + labels: { + $contained_by: ['important', 'work', 'urgent'] + } + } +}); +``` + +Through the REST API: + +``` +/messages?label[$contained_by][0]=important&label[$contained_by][1]=work&label[$contained_by][2]=urgent +``` + +### $overlap + +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` : + +```js +app.service('messages').find({ + query: { + labels: { + $overlap: ['important', 'work', 'urgent'] + } + } +}); +``` + +Through the REST API: + +``` +/messages?label[$overlap][0]=important&label[$overlap][1]=work&label[$overlap][2]=urgent +``` + ## Transaction Support diff --git a/lib/index.js b/lib/index.js index 84dd84a..b48f662 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,7 +23,10 @@ const OPERATORS = { $gte: '>=', $like: 'like', $notlike: 'not like', - $ilike: 'ilike' + $ilike: 'ilike', + $overlap: '&&', + $contains: '@>', + $contained_by: '<@' }; // Create the service. @@ -42,8 +45,8 @@ class Service extends AdapterService { super(Object.assign({ id: 'id' }, options, { - whitelist: whitelist.concat(['$like', '$notlike', '$ilike', '$and']) - })); + whitelist: whitelist.concat(['$like', '$notlike', '$ilike', '$and', '$overlap', '$contains', '$contained_by']) + })); this.table = options.name; this.schema = options.schema;