mirror of
https://github.com/supabase/supabase.git
synced 2026-10-19 08:09:11 +03:00
fix(sql-to-rest): multiple filters on same column
This commit is contained in:
1 parent
aaf0398a39
commit
a14ab014ee
2 files changed
+20
-2
No files matched your search
@@ -259,6 +259,24 @@ describe('select', () => {
|
||||
expect(fullPath).toBe('/books?title=eq.Cheese&description=ilike.*salsa*')
|
||||
})
|
||||
|
||||
test('"and" expression using the same column multiple times', async () => {
|
||||
const sql = stripIndents`
|
||||
select
|
||||
*
|
||||
from
|
||||
books
|
||||
where
|
||||
pages > 100 and
|
||||
pages < 1000
|
||||
`
|
||||
|
||||
const statement = await processSql(sql)
|
||||
const { method, fullPath } = await renderHttp(statement)
|
||||
|
||||
expect(method).toBe('GET')
|
||||
expect(fullPath).toBe('/books?pages=gt.100&pages=lt.1000')
|
||||
})
|
||||
|
||||
test('"or" expression', async () => {
|
||||
const sql = stripIndents`
|
||||
select
|
||||
|
||||
@@ -100,7 +100,7 @@ function formatSelectFilterRoot(params: URLSearchParams, filter: Filter) {
|
||||
value = filter.value.replaceAll('%', '*')
|
||||
}
|
||||
|
||||
params.set(filter.column, `${maybeNot}${filter.operator}.${value}`)
|
||||
params.append(filter.column, `${maybeNot}${filter.operator}.${value}`)
|
||||
}
|
||||
// Logical operator filter, eg. "or=(title.eq.Cheese,title.eq.Salsa)""
|
||||
else if (type === 'logical') {
|
||||
@@ -113,7 +113,7 @@ function formatSelectFilterRoot(params: URLSearchParams, filter: Filter) {
|
||||
}
|
||||
// Otherwise use the <operator>=(...) syntax
|
||||
else {
|
||||
params.set(
|
||||
params.append(
|
||||
`${maybeNot}${filter.operator}`,
|
||||
`(${filter.values.map((subFilter) => formatSelectFilter(subFilter)).join(',')})`
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user