RazorFlow/saberjs — pull request #1 by crodjer (2013-08-14 07:25:48+00:00)
Title: Support for filters on query set

This adds two methods `filter` and `where` to the query set. Borrowing from the test suit, this is how the API looks:

###filter

```javascript

var filterFunction = function filterFunction(model) {
return model.age > 21;
};

source.query(function (err, querySet) {
querySet.filter(filterFunction)
.execute(function (err, models) {
expect(models.length).toBe(expected.length);

Utils.each(models, function(model, index) {
expect(model).toEqual(expected[index]);
});
});
});
});
```

###where
```javascript
source.query(function (err, querySet) {
querySet.where({age: 23})
.execute(function (err, models) {
expect(models.length).toBe(expected.length);

Utils.each(models, function(model, index) {
expect(model).toEqual(expected[index]);
});
});
});

source.query(function (err, querySet) {
querySet.where('age', 23)
.execute(function (err, models) {
expect(models.length).toBe(expected.length);

Utils.each(models, function(model, index) {
expect(model).toEqual(expected[index]);
});
});
});

source.query(function (err, querySet) {
querySet.where()
.execute(function (err, models) {
expect(models.length).toBe(0);
});
});

source.query(function (err, querySet) {
querySet.where('age')
.execute(function (err, models) {
expect(models.length).toBe(0);
});
});
```

> For internal use, I have also added a generic filter utility, again borrowed from underscore.js.