{"id":13801851,"url":"https://github.com/jaredleechn/egg-rest-query","last_synced_at":"2025-07-31T08:12:59.062Z","repository":{"id":57220729,"uuid":"88057740","full_name":"jaredleechn/egg-rest-query","owner":"jaredleechn","description":null,"archived":false,"fork":false,"pushed_at":"2017-04-26T11:36:44.000Z","size":16,"stargazers_count":14,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-03-14T23:47:30.105Z","etag":null,"topics":["egg-plugin","mongodb","odata","query-parser"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredleechn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-12T13:55:56.000Z","updated_at":"2020-07-18T05:41:34.000Z","dependencies_parsed_at":"2022-08-29T04:01:46.006Z","dependency_job_id":null,"html_url":"https://github.com/jaredleechn/egg-rest-query","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredleechn%2Fegg-rest-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredleechn%2Fegg-rest-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredleechn%2Fegg-rest-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredleechn%2Fegg-rest-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredleechn","download_url":"https://codeload.github.com/jaredleechn/egg-rest-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223580397,"owners_count":17168621,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["egg-plugin","mongodb","odata","query-parser"],"created_at":"2024-08-04T00:01:28.632Z","updated_at":"2024-11-07T19:45:14.196Z","avatar_url":"https://github.com/jaredleechn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# egg-rest-query\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-rest-query.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-rest-query\n[travis-image]: https://img.shields.io/travis/jaredleechn/egg-rest-query.svg?style=flat-square\n[travis-url]: https://travis-ci.org/jaredleechn/egg-rest-query\n[codecov-image]: https://img.shields.io/codecov/c/github/jaredleechn/egg-rest-query.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/jaredleechn/egg-rest-query?branch=master\n[david-image]: https://img.shields.io/david/jaredleechn/egg-rest-query.svg?style=flat-square\n[david-url]: https://david-dm.org/jaredleechn/egg-rest-query\n[snyk-image]: https://snyk.io/test/npm/egg-rest-query/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-rest-query\n[download-image]: https://img.shields.io/npm/dm/egg-rest-query.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-rest-query\n\nparsing request query into usable db condition for mongoDB etc...\n\n```\nrequest: /api/product?fields=name\u0026sort=createdAt\u0026filter=productName eq basement and createdAt gt datetimeoffset'2017-03-28T16:40:09.724Z' and startswith(name, 'base')\n```\n\npatch parsing result into `ctx.extendQuery` with values:\n\n```js\n{\n  mongoFilter: {\n    $and: [{\n      productName: {\n        $eq: 'basement',\n      },\n    }, {\n      $and: [{\n        createdAt: {\n          $gt: { __type : 'date', iso: '2017-03-28T16:40:09.724Z' },\n        },\n      }, {\n        name: /^base/i,\n      }],\n    }],\n  },\n  mongoSort: 'createdAt',\n  mongoFields: 'name',\n}\n```\n\nand query in mongoDB\n\n```js\nconst { mongoFilter, mongoSort, mongoFields, mongoInclude, skip, top } = ctx.extendQuery;\nthis.db.class('product').find({\n  where: mongoFilter,\n  sort: mongoSort,\n  fields: mongoFields,\n  skip,\n  top,\n  include: mongoInclude,\n});\n```\n\nmore filter supported like startswith, endswith, substringof, view [odata-parser](https://github.com/auth0/node-odata-parser/blob/master/test/parser.specs.js)\n\n## Install\n\n```bash\n$ npm i egg-rest-query --save\n```\n\n## Usage\n\n```js\n// {app_root}/config/plugin.js\nexports['rest-query'] = {\n  enable: true,\n  package: 'egg-rest-query',\n};\n```\n\nthen `extendQuery` with be available on `ctx`\n\n## Configuration\n\n```js\n// {app_root}/config/config.default.js\nexports['rest-query'] = {\n};\n```\n\nsee [config/config.default.js](config/config.default.js) for more detail.\n\n## Example\n\n\u003c!-- example here --\u003e\n\n## Questions \u0026 Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredleechn%2Fegg-rest-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredleechn%2Fegg-rest-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredleechn%2Fegg-rest-query/lists"}