egg-rest-query
parsing request query into usable db condition for mongoDB etc...
request: /api/product?fields=name&sort=createdAt&filter=productName eq basement and createdAt gt datetimeoffset'2017-03-28T16:40:09.724Z' and startswith(name, 'base')
patch parsing result into ctx.extendQuery
with values:
mongoFilter: $and: productName: $eq: 'basement' $and: createdAt: $gt: __type : 'date' iso: '2017-03-28T16:40:09.724Z' name: /^base/i mongoSort: 'createdAt' mongoFields: 'name'
and query in mongoDB
const mongoFilter mongoSort mongoFields mongoInclude skip top = ctxextendQuery;thisdb;
more filter supported like startswith, endswith, substringof, view odata-parser
Install
$ npm i egg-rest-query --save
Usage
// {app_root}/config/plugin.jsexports'rest-query' = enable: true package: 'egg-rest-query';
then extendQuery
with be available on ctx
Configuration
// {app_root}/config/config.default.jsexports'rest-query' = ;
see config/config.default.js for more detail.
Example
Questions & Suggestions
Please open an issue here.