diff --git a/packages/core/database/src/__tests__/operator/notIn.test.ts b/packages/core/database/src/__tests__/operator/notIn.test.ts new file mode 100644 index 0000000000..03baab007c --- /dev/null +++ b/packages/core/database/src/__tests__/operator/notIn.test.ts @@ -0,0 +1,33 @@ +import { mockDatabase } from '../index'; +import Database from '../../database'; + +describe('ne operator', () => { + let db: Database; + let Test; + beforeEach(async () => { + db = mockDatabase({}); + + Test = db.collection({ + name: 'tests', + fields: [{ type: 'string', name: 'name' }], + }); + + await db.sync(); + }); + + afterEach(async () => { + await db.close(); + }); + + it('should notIn with null', async () => { + await db.getRepository('tests').create({}); + + const results = await db.getRepository('tests').count({ + filter: { + 'name.$notIn': ['123'], + }, + }); + + expect(results).toEqual(1); + }); +}); diff --git a/packages/core/database/src/operators/index.ts b/packages/core/database/src/operators/index.ts index f746f04b42..db4cbca8a7 100644 --- a/packages/core/database/src/operators/index.ts +++ b/packages/core/database/src/operators/index.ts @@ -5,4 +5,5 @@ export default { ...require('./empty').default, ...require('./string').default, ...require('./ne').default, + ...require('./notIn').default, }; diff --git a/packages/core/database/src/operators/notIn.ts b/packages/core/database/src/operators/notIn.ts new file mode 100644 index 0000000000..f5ad846014 --- /dev/null +++ b/packages/core/database/src/operators/notIn.ts @@ -0,0 +1,12 @@ +import { Op } from 'sequelize'; + +export default { + $notIn(val, ctx) { + return { + [Op.or]: { + [Op.notIn]: val, + [Op.is]: null, + }, + }; + }, +};