From 9aeaa37b1c355b7991aed264ffbea4a500cddfa6 Mon Sep 17 00:00:00 2001 From: "Daniel B. Vasquez" Date: Mon, 16 Mar 2015 11:21:04 +0100 Subject: [PATCH 1/2] enable between filter for memory db connector --- lib/connectors/memory.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/connectors/memory.js b/lib/connectors/memory.js index 91c00263..253ad19f 100644 --- a/lib/connectors/memory.js +++ b/lib/connectors/memory.js @@ -455,7 +455,12 @@ function applyFilter(filter) { if ('neq' in example) { return compare(example.neq, value) !== 0; } - + + if ('between' in example ) { + return ( testInEquality({gte:example.between[0]}, value) && + testInEquality({lte:example.between[1]}, value) ); + } + if (example.like || example.nlike) { var like = example.like || example.nlike; From 3de94cb9bda6639888e35e5864997932dcf4c784 Mon Sep 17 00:00:00 2001 From: "Daniel B. Vasquez" Date: Mon, 16 Mar 2015 18:26:33 +0100 Subject: [PATCH 2/2] add tests for between in memory connector --- test/memory.test.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/memory.test.js b/test/memory.test.js index a9cc627a..f3e6ab59 100644 --- a/test/memory.test.js +++ b/test/memory.test.js @@ -224,6 +224,38 @@ describe('Memory connector', function() { }); }); + it('should successfully extract 5 users from the db', function(done) { + User.find({where: {seq: {between: [1,5]}}}, function(err, users) { + should(users.length).be.equal(5); + done(); + }); + }); + + it('should successfully extract 1 user (Lennon) from the db', function(done) { + User.find({where: {birthday: {between: [new Date(1970,0),new Date(1990,0)]}}}, + function(err, users) { + should(users.length).be.equal(1); + should(users[0].name).be.equal('John Lennon'); + done(); + }); + }); + + it('should successfully extract 2 users from the db', function(done) { + User.find({where: {birthday: {between: [new Date(1940,0),new Date(1990,0)]}}}, + function(err, users) { + should(users.length).be.equal(2); + done(); + }); + }); + + it('should successfully extract 0 user from the db', function(done) { + User.find({where: {birthday: {between: [new Date(1990,0), Date.now()]}}}, + function(err, users) { + should(users.length).be.equal(0); + done(); + }); + }); + it('should support order with multiple fields', function(done) { User.find({order: 'vip ASC, seq DESC'}, function(err, posts) { should.not.exist(err);