All Projects → TRUEPIC → Queryql

TRUEPIC / Queryql

Licence: mit
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Queryql

spring-boot-jpa-rest-demo-filter-paging-sorting
Spring Boot Data JPA with Filter, Pagination and Sorting
Stars: ✭ 70 (-7.89%)
Mutual labels:  pagination, sorting, filter, sort, filtering
express-mquery
Expose mongoose query API through HTTP request.
Stars: ✭ 37 (-51.32%)
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 (+243.42%)
Mutual labels:  sort, query, filter, pagination
Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (+97.37%)
Mutual labels:  api, sort, query, filter
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+389.47%)
Mutual labels:  pagination, sorting, query, filtering
Rrda
REST API allowing to perform DNS queries over HTTP
Stars: ✭ 176 (+131.58%)
Mutual labels:  api, rest, query
repository
[PHP 7] Implementation and definition of a base Repository in Domain land.
Stars: ✭ 26 (-65.79%)
Mutual labels:  pagination, filter, sort
pimpable
No description or website provided.
Stars: ✭ 102 (+34.21%)
Mutual labels:  sorting, filter, filtering
ag-grid
The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.
Stars: ✭ 8,743 (+11403.95%)
Mutual labels:  pagination, sorting, filtering
react-strap-table
react table (client and server-side) based on bootstrap.
Stars: ✭ 28 (-63.16%)
Mutual labels:  pagination, sorting, filter
Foal
Elegant and all-inclusive Node.Js web framework based on TypeScript. 🚀.
Stars: ✭ 1,176 (+1447.37%)
Mutual labels:  api, rest, orm
Jsonapi.rb
Lightweight, simple and maintained JSON:API support for your next Ruby HTTP API.
Stars: ✭ 116 (+52.63%)
Mutual labels:  api, filter, pagination
Walkable
A Clojure(script) SQL library for building APIs: Datomic® (GraphQL-ish) pull syntax, data driven configuration, dynamic filtering with relations in mind
Stars: ✭ 384 (+405.26%)
Mutual labels:  orm, query, filter
Filterizr
✨ Filterizr is a JavaScript library that sorts, shuffles and filters responsive galleries using CSS3 transitions ✨
Stars: ✭ 546 (+618.42%)
Mutual labels:  sort, filtering, filter
Queryablelist
Python module to add support for ORM-style filtering to any list of items
Stars: ✭ 19 (-75%)
Mutual labels:  orm, query, filter
Rummage ecto
Search, Sort and Pagination for ecto queries
Stars: ✭ 190 (+150%)
Mutual labels:  sort, pagination, sorting
React Table
⚛️ Hooks for building fast and extendable tables and datagrids for React
Stars: ✭ 15,739 (+20609.21%)
Mutual labels:  filtering, pagination, sorting
Rummage phoenix
Full Phoenix Support for Rummage. It can be used for searching, sorting and paginating collections in phoenix.
Stars: ✭ 144 (+89.47%)
Mutual labels:  sort, pagination, sorting
Gridjs
Advanced table plugin
Stars: ✭ 3,231 (+4151.32%)
Mutual labels:  sort, filter, pagination
Sieve
⚗️ Clean & extensible Sorting, Filtering, and Pagination for ASP.NET Core
Stars: ✭ 560 (+636.84%)
Mutual labels:  sort, filter, pagination

QueryQL

npm CircleCI piratepx

QueryQL makes it easy to add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string! Read our introductory article to learn more about why we wrote it and the problems it solves at Truepic.

QueryQL works with any Node.js web framework (be it Express, Koa, etc.), supports any query builder / ORM through adapters, and allows for custom validators so you can define validation in a familiar way.

Out of the box, QueryQL supports the following:

Installation

$ npm install @truepic/queryql

Getting Started

QueryQL takes a parsed query string (like Express' req.query) and translates it into the appropriate function calls that your query builder / ORM understands to filter, sort, and paginate the records.

Let's consider an example to illustrate:

/images?filter[id][in][]=2&filter[id][in][]=3&filter[status]=open&sort=name&page[size]=10
{
  filter: {
    id: {
      in: [2, 3],
    },
    status: 'open',
  },
  sort: 'name',
  page: {
    size: 10,
  },
}

To support this query, QueryQL only requires you to define (whitelist) what's allowed through what we call a querier. Here's how one might look for the /images endpoint:

const QueryQL = require('@truepic/queryql')

class ImageQuerier extends QueryQL {
  defineSchema(schema) {
    schema.filter('id', 'in')
    schema.filter('status', '=')
    schema.sort('name')
    schema.page()
  }
}

With your querier defined, you can now call it in your router / controller. Here's how it might look in an Express route:

app.get('/images', async (req, res, next) => {
  const querier = new ImageQuerier(req.query, knex('images'))
  let images

  try {
    images = await querier.run()
  } catch (error) {
    // Handle validation error, such as by passing to an Express error handler:
    next(error)
  }

  res.send({ images })
})

Behind-the-scenes, QueryQL takes your initial query builder (knex('images')), and applies the following Knex chain when querier.run() is called:

builder
  .where('id', 'in', [2, 3])
  .where('status', '=', 'open')
  .orderBy('name', 'asc')
  .limit(10)
  .offset(0)

(Remember: While Knex is our default adapter and the query builder used in this example, adapters can be written for any query builder / ORM.)

This is a simple example, but hopefully it illustrates how easy it is to add filtering, sorting, and pagination to your REST API without manually touching your query builder / ORM.

Read the full documentation to learn how to add validation, customize the queries, and more.

Development

Prerequisites

The only prerequisite is a compatible version of Node.js (see engines.node in package.json).

Dependencies

Install dependencies with npm:

$ npm install

Tests

Jest is our testing framework of choice, with file-specific tests contained in the test/src directory. We strive for 100% code coverage.

To run the tests:

$ npm test

During development, it's recommended to run the tests automatically on file change:

$ npm test -- --watch [--notify]

Code Style & Linting

Prettier is setup to enforce a consistent code style. It's highly recommended to add an integration to your editor that automatically formats on save.

ESLint is setup with the "recommended" rules to enforce a level of code quality. It's also highly recommended to add an integration to your editor that automatically formats on save.

To run via the command line:

$ npm run lint

Releasing

After development is done in the development branch and is ready for release, it should be merged into the master branch, where the latest release code lives. Release It! is then used to interactively orchestrate the release process:

$ npm run release
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].