Not Contains for SQL Server

This commit is contained in:
Mel O'Hagan 2022-07-27 11:56:57 +01:00
parent 69135d34a7
commit 413bd55b94
2 changed files with 6 additions and 4 deletions

View File

@ -176,7 +176,9 @@ class InternalBuilder {
const columnName = fieldNames[1]
// @ts-ignore
query = query[rawFnc](
`${not}"${tableName}"."${columnName}"::jsonb @> ${stringifyArray(value)}`
`${not}"${tableName}"."${columnName}"::jsonb @> ${stringifyArray(
value
)}`
)
})
} else if (this.client === SqlClients.MY_SQL) {
@ -200,7 +202,7 @@ class InternalBuilder {
`LOWER(${likeKey(this.client, key)}) LIKE ?`
}
// @ts-ignore
query = query[rawFnc](andStatement, value)
query = query[rawFnc](`${not}(${andStatement})`, value)
})
}
}

View File

@ -285,7 +285,7 @@ describe("SQL query builder", () => {
})
})
it("should use like expression for MS-SQL when filter is notContains", () => {
it("should use NOT like expression for MS-SQL when filter is notContains", () => {
const query = new Sql(SqlClients.MS_SQL, 10)._query(generateReadJson({
filters: {
notContains: {
@ -296,7 +296,7 @@ describe("SQL query builder", () => {
}))
expect(query).toEqual({
bindings: [10, "%20%", `%"John"%`],
sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where LOWER(${TABLE_NAME}.age) LIKE @p1 and LOWER(${TABLE_NAME}.name) LIKE @p2) as [${TABLE_NAME}]`
sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where NOT (LOWER(${TABLE_NAME}.age) LIKE @p1) and NOT (LOWER(${TABLE_NAME}.name) LIKE @p2)) as [${TABLE_NAME}]`
})
})