Skip to content

Commit 80a8bbd

Browse files
committed
LIKE operator support
1 parent 70e4f36 commit 80a8bbd

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ function filterQuery(resourceConfig, params) {
6868
query = query.where(field, 'in', v);
6969
} else if (op === 'notIn') {
7070
query = query.whereNotIn(field, v);
71+
} else if (op === 'like') {
72+
query = query.where(field, 'like', v);
7173
} else if (op === '|==' || op === '|===') {
7274
query = query.orWhere(field, v);
7375
} else if (op === '|!=' || op === '|!==') {

test/findAll.spec.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('DSSqlAdapter#findAll', function () {
2323
it('should filter users using the "in" operator', function () {
2424
var id;
2525

26-
adapter.findAll(User, {
26+
return adapter.findAll(User, {
2727
where: {
2828
age: {
2929
'in': [30]
@@ -45,4 +45,33 @@ describe('DSSqlAdapter#findAll', function () {
4545
assert.isFalse(!!destroyedUser);
4646
});
4747
});
48+
it('should filter users using the "like" operator', function () {
49+
var id;
50+
51+
return adapter.findAll(User, {
52+
where: {
53+
name: {
54+
'like': '%J%'
55+
}
56+
}
57+
}).then(function (users) {
58+
assert.equal(users.length, 0);
59+
return adapter.create(User, { name: 'John' });
60+
}).then(function (user) {
61+
id = user.id;
62+
return adapter.findAll(User, {
63+
where: {
64+
name: {
65+
'like': '%J%'
66+
}
67+
}
68+
});
69+
}).then(function (users) {
70+
assert.equal(users.length, 1);
71+
assert.deepEqual(users[0], { id: id, name: 'John', age: null });
72+
return adapter.destroy(User, id);
73+
}).then(function (destroyedUser) {
74+
assert.isFalse(!!destroyedUser);
75+
});
76+
});
4877
});

0 commit comments

Comments
 (0)