UNPKG

2.13 kBMarkdownView Raw
1# @36node/query-normalizr
2
3[![version][0]][1] [![downloads][2]][3]
4
5这里 query-normalizr 的作用: 将经过类型转换的 koa query 规则化成对应数据库的 query。
6
7## Install
8
9```bash
10yarn add @36node/query-normalizr
11```
12
13## Usage
14
15```js
16import { toMongooseQuery } from "@36node/query-normalizr";
17
18console.log(rawQuery);
19/*
20{
21 _limit: 10,
22 _offset: 10,
23 _sort: "-createdBy",
24 _populate: "user",
25 _select: ["views", "body"],
26 _group: ["ns", "author"],
27 age_lt: 10,
28 age_gt: 5,
29 tag_ne: "pretty",
30 name: "sherry",
31 title_like: "hello",
32 assignees: "*",
33 followers: "none",
34 q: hello"
35};
36*/
37const mQuery = toMongooseQuery(rawQuery);
38console.log(mQuery);
39/*
40{
41 limit: 10,
42 offset: 10,
43 sort: "-createdBy", // if array should be: ["-createdBy", "views"]
44 select: ["views", "body"], // if single should be: "views"
45 group: ["ns", "author"], // group by
46 populate: "author",
47 filter: {
48 age: {
49 $lt: 10, // age_lt
50 $gt: 5, // age_gt
51 },
52 tag: {
53 $ne: "pretty", // tag_ne
54 },
55 name: "sherry",
56 title: /hello/i, // like
57 assignees: { $ne: [] },
58 followers: { $eq: [] },
59 $text: { $search: "hello" }
60 }
61}
62*/
63```
64
65### Query in route (QIR)
66
67reference in [url.md](../../docs/url.md)
68
69## Contributing
70
711. Fork it!
722. Create your feature branch: `git checkout -b my-new-feature`
733. Commit your changes: `git commit -am 'Add some feature'`
744. Push to the branch: `git push origin my-new-feature`
755. Submit a pull request :D
76
77## Author
78
79**query-normalizr** © [36node](https://github.com/36node), Released under the [MIT](./LICENSE) License.
80
81Authored and maintained by 36node with help from contributors ([list](https://github.com/36node/query-normalizr/contributors)).
82
83> [github.com/zzswang](https://github.com/zzswang) · GitHub [@36node](https://github.com/36node) · Twitter [@y](https://twitter.com/y)
84
85[0]: https://img.shields.io/npm/v/@36node/query-normalizr.svg?style=flat
86[1]: https://npmjs.com/package/@36node/query-normalizr
87[2]: https://img.shields.io/npm/dm/@36node/query-normalizr.svg?style=flat
88[3]: https://npmjs.com/package/@36node/query-normalizr