fix: not in operator with null value record (#377)

This commit is contained in:
ChengLei Shao 2022-05-13 11:16:57 +08:00 committed by GitHub
parent c4b5f4f84b
commit 0467093dfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View File

@ -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);
});
});

View File

@ -5,4 +5,5 @@ export default {
...require('./empty').default, ...require('./empty').default,
...require('./string').default, ...require('./string').default,
...require('./ne').default, ...require('./ne').default,
...require('./notIn').default,
}; };

View File

@ -0,0 +1,12 @@
import { Op } from 'sequelize';
export default {
$notIn(val, ctx) {
return {
[Op.or]: {
[Op.notIn]: val,
[Op.is]: null,
},
};
},
};