fix(sql-to-rest): multiple filters on same column

This commit is contained in:
Greg Richardson committed 2024-05-09 11:33:54 -06:00
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
+2 -2
View File
@@ -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(',')})`
)