feat: ne operator (#233)
This commit is contained in:
parent
627e2a9f4c
commit
fe8c2576d0
33
packages/database/src/__tests__/operator/ne.test.ts
Normal file
33
packages/database/src/__tests__/operator/ne.test.ts
Normal 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);
|
||||
});
|
||||
});
|
@ -4,4 +4,5 @@ export default {
|
||||
...require('./array').default,
|
||||
...require('./empty').default,
|
||||
...require('./string').default,
|
||||
...require('./ne').default,
|
||||
};
|
||||
|
12
packages/database/src/operators/ne.ts
Normal file
12
packages/database/src/operators/ne.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Op } from 'sequelize';
|
||||
|
||||
export default {
|
||||
$ne(val, ctx) {
|
||||
return {
|
||||
[Op.or]: {
|
||||
[Op.ne]: val,
|
||||
[Op.is]: null,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue
Block a user