All Projects → lykmapipo → express-mquery

lykmapipo / express-mquery

Licence: MIT license
Expose mongoose query API through HTTP request.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to express-mquery

Queryql
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!
Stars: ✭ 76 (+105.41%)
Mutual labels:  pagination, query, filter, sort
Graphql To Mongodb
Allows for generic run-time generation of filter types for existing graphql types and parsing client requests to mongodb find queries
Stars: ✭ 261 (+605.41%)
Mutual labels:  pagination, query, filter, sort
List.js
The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML.
Stars: ✭ 10,650 (+28683.78%)
Mutual labels:  pagination, sort, filters
Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (+305.41%)
Mutual labels:  query, filter, sort
Exopite-Multifilter-Multi-Sorter-WordPress-Plugin
Display and/or sort/filter any page or post types by multiple taxonomies or terms (like post by categories and/or tags) with AJAX. Exopite multifilter, multi-sortable, multi selectable, multi filterable sortable Wordpress Plugin.
Stars: ✭ 18 (-51.35%)
Mutual labels:  pagination, filter, filters
Sieve
⚗️ Clean & extensible Sorting, Filtering, and Pagination for ASP.NET Core
Stars: ✭ 560 (+1413.51%)
Mutual labels:  pagination, filter, sort
spring-boot-jpa-rest-demo-filter-paging-sorting
Spring Boot Data JPA with Filter, Pagination and Sorting
Stars: ✭ 70 (+89.19%)
Mutual labels:  pagination, filter, sort
Gridjs
Advanced table plugin
Stars: ✭ 3,231 (+8632.43%)
Mutual labels:  pagination, filter, sort
Jsonapi.rb
Lightweight, simple and maintained JSON:API support for your next Ruby HTTP API.
Stars: ✭ 116 (+213.51%)
Mutual labels:  pagination, json-api, filter
repository
[PHP 7] Implementation and definition of a base Repository in Domain land.
Stars: ✭ 26 (-29.73%)
Mutual labels:  pagination, filter, sort
commerce
🛒 e-commerce-platform
Stars: ✭ 54 (+45.95%)
Mutual labels:  mongoose, expressjs
cargo-limit
Cargo with less noise: warnings are skipped until errors are fixed, Neovim integration, etc.
Stars: ✭ 105 (+183.78%)
Mutual labels:  filter, limit
typijs
The Angular CMS Framework for building fully-featured SPA sites powered by NodeJS and MongoDB with TypeScript
Stars: ✭ 141 (+281.08%)
Mutual labels:  mongoose, expressjs
search-cities
No description or website provided.
Stars: ✭ 11 (-70.27%)
Mutual labels:  mongoose, expressjs
api
_api is an autogenerated CRUD API built on LowDB and ExpressJS.
Stars: ✭ 73 (+97.3%)
Mutual labels:  json-api, expressjs
Natours
An awesome tour booking web app written in NodeJS, Express, MongoDB 🗽
Stars: ✭ 94 (+154.05%)
Mutual labels:  mongoose, expressjs
aarbac
An Automated Role Based Access Control .NET framework with T-SQL Query Parser which automatically parse select, insert, update, delete queries based on the logged in user role
Stars: ✭ 18 (-51.35%)
Mutual labels:  query, filters
MERN-JWT-AND-ROLE-AUTH
Neccessary features needed for your mern Application are now available.
Stars: ✭ 30 (-18.92%)
Mutual labels:  mongoose, expressjs
mern-stack-crud
MERN stack (MongoDB, Express, React and Node.js) create read update and delete (CRUD) web application example
Stars: ✭ 142 (+283.78%)
Mutual labels:  mongoose, expressjs
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+905.41%)
Mutual labels:  pagination, query

express-mquery

Build Status Dependencies Status Coverage Status GitHub License

Commitizen Friendly code style: prettier Code Style npm version

Expose mongoose query API through HTTP request with partial support of json-api:

Note: Checkout the current specification for more information.

Installation

$ npm install --save express-mquery

Usage

import expess from 'express';
import mquery from 'express-mquery';

const app = express();
app.use(mquery({ limit: 10, maxLimit: 50 }));

...

app.get('/users', (request, response, next) => {
  
  // obtain request.mquery
  console.log(request.mquery);

});

Structure

Once parse, express-mquery will extend http request with mquery field

Example:

GET /invoices?fields=number,amount&filter[name]=Bob
&filter[amount][$gte]=1200&include=customer,items
&fields[customer]=name,number&fields[items]=name,price
&page[number]=1&page[size]=10&sort[number]=1&sort[amount]=-1

Will be parsed into:

{
  filter: { name: "Bob", amount: { $gte: 1200 } },
  paginate: { limit: 10, skip: 0, page: 1 },
  populate: [
  	{ path: "customer", select: { name: 1, number: 1 } },
  	{ path: "items", select: { name: 1, price: 1 } }
  ],
  select: { number: 1, amount: 1 },
  sort: { number: 1, amount: -1 }
}

Where:

  • filter : Is valid mongoose criteria and can be passed to find()
  • paginate : Contains paging details that can be passed to limit(), skip()
  • populate : Is valid mongoose populate option and can be passed to populate()
  • select : Is valid mongoose project options and can be passed to select()
  • sort : Is valid mongoose sort options and can be passed to sort()

Querying

When passing values as objects or arrays in URLs, they must be valid JSON

Sort

GET /customers?sort=name
GET /customers?sort=-name
GET /customers?sort={"name":1}
GET /customers?sort={"name":1, "email":-1}

or

GET /customers?sort=name
GET /customers?sort=-name
GET /customers?sort[name]=1&sort[email]=-1

Page

GET /customers?page=1
GET /customers?page=1&limit=10
GET /customers?page[number]=1&page[size]=10

Skip

GET /customers?skip=10

Limit

Only overrides maximum limit option set by the plugin if the queried limit is lower

GET /customers?limit=10

Query or Filters

Supports all mongodb operators ($regex, $gt, $gte, $lt, $lte, $ne, etc.)

GET /customers?query={"name":"Bob"}
GET /customers?query={"name":{"$regex":"/Bo$/"}}
GET /customers?query={"age":{"$gt":12}}
GET /customers?query={"age":{"$gte":12}}

or

GET /customers?filter[name]=Bob
GET /customers?filter[name][$regex]="/Bo$/"
GET /customers?filter[age][$gt]=12
GET /customers?filter[age][$gte]=12

Populate or Include

Works with create, read and update operations

GET /invoices?populate=customer
GET /invoices?populate={"path":"customer"}
GET /invoices?populate=[{"path":"customer"},{"path":"products"}]

or

GET /invoices?include=customer
GET /invoices?include[customer]=name,number&includes[items]=name,price
GET /invoices?include=customer,items&fields[customer]=name,number&fields[items]=name,price

Select or Fields

_id is always returned unless explicitely excluded

GET /customers?select=name
GET /customers?select=-name
GET /customers?select={"name":1}
GET /customers?select={"name":0}

or

GET /customers?fields=name
GET /customers?fields=-name
GET /customers?fields=name,email
GET /invoices?include=customer&fields[customer]=name

Testing

  • Clone this repository

  • Install grunt-cli global

$ npm install -g grunt-cli
  • Install all development dependencies
$ npm install
  • Then run test
$ npm test

Contribute

Fork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.

Licence

Copyright (c) lykmapipo & Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].