Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 3dbc6a4

Browse files
authored
Merge pull request #80 from supabase/feat/or
feat: support OR filter
2 parents b9053b8 + 475de12 commit 3dbc6a4

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/Builder.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class Builder {
4545
request.not(queryFilter.columnName, queryFilter.operator, queryFilter.criteria)
4646
break
4747

48+
case 'or':
49+
request.or(queryFilter.filters)
50+
break
51+
4852
case 'match':
4953
request.match(queryFilter.query)
5054
break
@@ -97,6 +101,15 @@ class Builder {
97101
return this
98102
}
99103

104+
or(filters) {
105+
this.queryFilters.push({
106+
filter: 'or',
107+
filters,
108+
})
109+
110+
return this
111+
}
112+
100113
match(query) {
101114
this.queryFilters.push({
102115
filter: 'match',

src/Request.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ const filters = [
332332
'nxr',
333333
'nxl',
334334
'adj',
335+
'or',
335336
]
336337
filters.forEach(
337338
(filter) =>

src/utils/Filters.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,19 @@ export function _nxr(columnName, filterRange) {
481481
export function _adj(columnName, filterRange) {
482482
return `${columnName}=adj.(${filterRange.join(',')})`
483483
}
484+
485+
/**
486+
* Finds all rows that satisfy at least one of the specified `filters`.
487+
* @param {string} filters Filters to satisfy
488+
* @name or
489+
* @function
490+
* @returns {string}
491+
*
492+
* @example
493+
* _or('id.gt.20,and(name.eq.New Zealand,name.eq.France)')
494+
* //=>
495+
* 'or=(id.gt.20,and(name.eq.New Zealand,name.eq.France))'
496+
*/
497+
export function _or(filters) {
498+
return `or=(${filters})`
499+
}

test/integration/Filters.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ describe('Filters', () => {
211211
'population_range=nxl.(100,500)',
212212
'population_range=nxr.(100,500)',
213213
'population_range=adj.(100,500)',
214+
'or=(id.gt.20,and(name.eq.New Zealand,name.eq.France))',
214215
]
215216

216217
it('should be able to take in filters before an actual request is made', async () => {
@@ -240,11 +241,13 @@ describe('Filters', () => {
240241
.nxl('population_range', [100, 500])
241242
.nxr('population_range', [100, 500])
242243
.adj('population_range', [100, 500])
244+
.or('id.gt.20,and(name.eq.New Zealand,name.eq.France)')
243245
.select('*')
244246

245247
assert.deepEqual(response._query, expectedQueryArray)
246248
})
247249

250+
// FIXME: This is still before a request is made.
248251
it('should be able to take in filters after an actual request is made', async () => {
249252
const client = new PostgrestClient(rootUrl)
250253
const response = client
@@ -273,6 +276,7 @@ describe('Filters', () => {
273276
.nxl('population_range', [100, 500])
274277
.nxr('population_range', [100, 500])
275278
.adj('population_range', [100, 500])
279+
.or('id.gt.20,and(name.eq.New Zealand,name.eq.France)')
276280

277281
assert.deepEqual(response._query, expectedQueryArray)
278282
})

0 commit comments

Comments
 (0)