feat: ne operator (#233)

This commit is contained in:
ChengLei Shao 2022-03-13 19:34:24 +08:00 committed by GitHub
parent 627e2a9f4c
commit fe8c2576d0
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 ne with null', async () => {
await db.getRepository('tests').create({});
const results = await db.getRepository('tests').count({
filter: {
'name.$ne': '123',
},
});
expect(results).toEqual(1);
});
});

View File

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

View File

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