From 191f4bfa93d714cdde4a4688042774787ceecc92 Mon Sep 17 00:00:00 2001 From: Greg Date: Sun, 10 Nov 2019 21:23:07 -0800 Subject: [PATCH 1/2] add $contains, $contained_by, and $overlap operators --- README.md | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/index.js | 9 +++++--- 2 files changed, 66 insertions(+), 3 deletions(-) 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; From ee62eb03df74c26aad0512229ccf2d1ae4c3b018 Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 10 Jan 2023 20:21:51 -0800 Subject: [PATCH 2/2] add fulltext operator --- README.md | 19 +++++++++++++++++++ lib/index.js | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a86c0de..74aa0a2 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,25 @@ Through the REST API: /messages?label[$overlap][0]=important&label[$overlap][1]=work&label[$overlap][2]=urgent ``` +### $fulltext + +For PostgreSQL only, for fulltext-indexed fields, finds records that match useing postgres' fulltext natural-langauge search. 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 +``` ## Transaction Support diff --git a/lib/index.js b/lib/index.js index b48f662..4b82c70 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26,7 +26,8 @@ const OPERATORS = { $ilike: 'ilike', $overlap: '&&', $contains: '@>', - $contained_by: '<@' + $contained_by: '<@', + $fulltext: '@@' }; // Create the service. @@ -45,7 +46,7 @@ class Service extends AdapterService { super(Object.assign({ id: 'id' }, options, { - whitelist: whitelist.concat(['$like', '$notlike', '$ilike', '$and', '$overlap', '$contains', '$contained_by']) + whitelist: whitelist.concat(['$like', '$notlike', '$ilike', '$and', '$overlap', '$contains', '$contained_by', '$fulltext']) })); this.table = options.name;