@36node/query-normalizr
A module boilerplate for nodejs and web.
Last updated 2 months ago by zzswang .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @36node/query-normalizr 
SYNC missed versions from official npm registry.

@36node/query-normalizr

version downloads

这里 query-normalizr 的作用: 将经过类型转换的 koa query 规则化成对应数据库的 query。

Install

yarn add @36node/query-normalizr

Usage

import { toMongooseQuery } from "@36node/query-normalizr";

console.log(rawQuery);
/*
{
  _limit: 10,
  _offset: 10,
  _sort: "-createdBy",
  _populate: "user",
  _select: ["views", "body"],
  _group: ["ns", "author"],
  age_lt: 10,
  age_gt: 5,
  tag_ne: "pretty",
  name: "sherry",
  title_like: "hello",
  assignees: "*",
  followers: "none",
  q: hello"
};
*/
const mQuery = toMongooseQuery(rawQuery);
console.log(mQuery);
/*
{
  limit: 10,
  offset: 10,
  sort: "-createdBy", // if array should be: ["-createdBy", "views"]
  select: ["views", "body"], // if single should be: "views"
  group: ["ns", "author"], // group by
  populate: "author",
  filter: {
    age: {
      $lt: 10,  // age_lt
      $gt: 5,   // age_gt
    },
    tag: {
      $ne: "pretty",  // tag_ne
    },
    name: "sherry",
    title: /hello/i,  // like
    assignees: { $ne: [] },
    followers: { $eq: [] },
    $text: { $search: "hello" }
  }
}
*/

Query in route (QIR)

reference in url.md

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

query-normalizr © 36node, Released under the MIT License.

Authored and maintained by 36node with help from contributors (list).

github.com/zzswang · GitHub @36node · Twitter @y

Current Tags

  • 0.5.0                                ...           latest (2 months ago)

16 Versions

  • 0.5.0                                ...           2 months ago
  • 0.4.8                                ...           10 months ago
  • 0.4.6                                ...           a year ago
  • 0.4.5                                ...           a year ago
  • 0.4.4                                ...           a year ago
  • 0.4.3                                ...           a year ago
  • 0.4.2                                ...           a year ago
  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.2.3                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago

Copyright 2014 - 2016 © taobao.org |