Browse Source

Not Contains Postgres filter

master
Mel O'Hagan 4 years ago
parent
commit
54643cff58
  1. 2
      packages/server/src/integrations/base/sql.ts
  2. 4
      packages/server/src/integrations/tests/sql.spec.js

2
packages/server/src/integrations/base/sql.ts

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

4
packages/server/src/integrations/tests/sql.spec.js

@ -315,7 +315,7 @@ describe("SQL query builder", () => {
})
})
it("should use jsonb operator expression for PostgreSQL when filter is notContains", () => {
it("should use jsonb operator NOT expression for PostgreSQL when filter is notContains", () => {
const query = new Sql(SqlClients.POSTGRES, 10)._query(generateReadJson({
filters: {
notContains: {
@ -326,7 +326,7 @@ describe("SQL query builder", () => {
}))
expect(query).toEqual({
bindings: [10],
sql: `select * from (select * from \"${TABLE_NAME}\" where \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"`
sql: `select * from (select * from \"${TABLE_NAME}\" where NOT \"${TABLE_NAME}\".\"age\"::jsonb @> '[20]' and NOT \"${TABLE_NAME}\".\"name\"::jsonb @> '["John"]' limit $1) as \"${TABLE_NAME}\"`
})
})
})

Loading…
Cancel
Save