diff --git a/packages/server/src/integrations/base/sql.ts b/packages/server/src/integrations/base/sql.ts index 28d24645f7..5a0151c4d4 100644 --- a/packages/server/src/integrations/base/sql.ts +++ b/packages/server/src/integrations/base/sql.ts @@ -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) }) } } diff --git a/packages/server/src/integrations/tests/sql.spec.js b/packages/server/src/integrations/tests/sql.spec.js index 1dff477d9d..4d1d031458 100644 --- a/packages/server/src/integrations/tests/sql.spec.js +++ b/packages/server/src/integrations/tests/sql.spec.js @@ -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}]` }) })