feathers-query-filters
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -13,3 +13,4 @@ /** | ||
$skip: query.$skip, | ||
$select: query.$select | ||
$select: query.$select, | ||
$populate: query.$populate | ||
}; | ||
@@ -22,2 +23,3 @@ | ||
delete query.$select; | ||
delete query.$populate; | ||
@@ -24,0 +26,0 @@ return filters; |
{ | ||
"name": "feathers-query-filters", | ||
"description": "Allows query string filtering of data in Feathers", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/feathersjs/feathers-query-filters", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -9,2 +9,3 @@ feathers-query-filters | ||
[![Build Status](https://travis-ci.org/feathersjs/feathers-query-filters.png?branch=master)](https://travis-ci.org/feathersjs/feathers-query-filters) | ||
[![Code Climate](https://codeclimate.com/github/feathersjs/feathers--query-filters.png)](https://codeclimate.com/github/feathersjs/feathers--query-filters) | ||
@@ -18,6 +19,68 @@ ## Installation | ||
## Getting Started | ||
This is used internally in service adapters like [Feathers MongoDB]() and [Feathers NeDB](). | ||
Usage is like so: | ||
```js | ||
var Proto = require('uberproto'); | ||
var filter = require('feathers-query-filters'); | ||
var CustomService = Proto.extend({ | ||
init: function(name, options){ | ||
// your custom initialization code | ||
}, | ||
find: function(params, callback) { | ||
// Start with finding all, and limit when necessary. | ||
var query = this.db.find({}); | ||
// Prepare the special query params. | ||
if (params.query) { | ||
var filters = filter(params.query); | ||
// $select uses a specific find syntax, so it has to come first. | ||
if (filters.$select) { | ||
query = this.db.find(params.query, filters.$select); | ||
} else { | ||
query = this.db.find(params.query); | ||
} | ||
// Handle $sort | ||
if (filters.$sort){ | ||
query.sort(filters.$sort); | ||
} | ||
// Handle $limit | ||
if (filters.$limit){ | ||
query.limit(filters.$limit); | ||
} | ||
// Handle $skip | ||
if (filters.$skip){ | ||
query.skip(filters.$skip); | ||
} | ||
} | ||
// Execute the query | ||
query.exec(function(err, docs) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return callback(err, docs); | ||
}); | ||
}, | ||
setup: function(app) { | ||
// Called by feathers.configure() | ||
this.app = app; | ||
this.service = app.service.bind(app); | ||
} | ||
}); | ||
module.exports = CustomService; | ||
``` | ||
## API | ||
The following keywords are supported. They are pulled from the query object's conditions and returned so they can be mapped by each adapter in their own way. | ||
### $sort | ||
@@ -31,6 +94,14 @@ | ||
### $populate | ||
## Changelog | ||
### 1.1.0 | ||
- Adding support for `$populate` | ||
### 1.0.1 | ||
- Adding usage docs | ||
### 1.0.0 | ||
* Initial release. | ||
- Initial release. | ||
@@ -37,0 +108,0 @@ ## License |
@@ -94,2 +94,24 @@ var chai = require('chai'); | ||
}); | ||
describe('$populate', function(){ | ||
beforeEach(function(){ | ||
this.query = { $populate: 1 }; | ||
}); | ||
it('returns $populate when present in query', function() { | ||
var result = filter(this.query); | ||
expect(result.$populate).to.equal(1); | ||
}); | ||
it('removes $populate from query when present', function() { | ||
filter(this.query); | ||
expect(this.query).to.deep.equal({}); | ||
}); | ||
it('returns undefined when not present in query', function() { | ||
var query = { $foo: 1 }; | ||
var result = filter(query); | ||
expect(result.$populate).to.be.undefined; | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10396
9
117
112