Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Fix #358 case-insensitive filter #360

Merged
merged 3 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions __tests__/lib/pg/odata-string-functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,12 @@ describe.each(suiteEnvironments)(
expect.arrayContaining([expect.objectContaining({ name: 'Schönramer Hell' })])
)
})

test('case-insensitive', async () => {
const response = await request.get(`/beershop/Beers?$filter=contains(name,'bi')`)
expect(response.status).toStrictEqual(200)
expect(response.body.value.length).toEqual(7)
expect(response.body.value).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'Bitter 42' })]))
})
}
)
11 changes: 11 additions & 0 deletions lib/pg/sql-builder/FunctionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ class PGFunctionBuilder extends FunctionBuilder {
this._outputObj.sql.push(')')
}
}

_createLikeComparisonForColumn(not, left, right) {
if (not) {
this._outputObj.sql.push('(', left, 'IS NULL', 'OR')
}

this._outputObj.sql.push(left, `${not}ILIKE`) // This 'ILIKE' change case-sensitive issue #358.
this._addFunctionArgs(right, true, ' || ')
this._outputObj.sql.push('ESCAPE', "'^'")
if (not) this._outputObj.sql.push(')')
}
}

module.exports = PGFunctionBuilder