Skip to content

Commit adcb768

Browse files
author
making3
committed
Added support and a test for the LIKE operator.
1 parent 97d6798 commit adcb768

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/mysql.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ MySQL.prototype.all = function all(model, filter, callback) {
320320
case 'neq':
321321
sqlCond += ' != ';
322322
break;
323+
case 'like':
324+
sqlCond += ' LIKE ';
325+
break;
323326
}
324327
sqlCond += (condType == 'inq' || condType == 'nin') ? '(' + val + ')' : val;
325328
cs.push(sqlCond);

test/basic-querying.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,24 @@ describe('basic-query-mysql', function() {
2424
done();
2525
});
2626
});
27+
2728
it('should query collection where order is 1 or 5', function(done) {
28-
UserData.all({where: { or: [{order: 1}, {order: 5}] }}, function(err, users) {
29+
UserData.all({ where: { or: [{order: 1}, {order: 5}] }}, function(err, users) {
2930
should.exists(users);
3031
should.not.exists(err);
3132
users.should.have.lengthOf(2);
3233
done();
3334
});
3435
});
36+
37+
it('should query collection where name like Len', function(done) {
38+
UserData.all({ where: { name: { like: '%Len%' }}}, function(err, users) {
39+
should.exists(users);
40+
should.not.exists(err);
41+
users.should.have.lengthOf(1);
42+
done();
43+
});
44+
});
3545
});
3646

3747
function seed(done) {

0 commit comments

Comments
 (0)