0.4.1 • Published 4 years ago

sequery v0.4.1

Weekly downloads
134
License
MIT
Repository
github
Last release
4 years ago

Sequery

Automatically parse nested query string parameters into Sequelize find options.

Uses the module qs to parse a provided query string then returns an Sequelize compatible object with find options.

Better docs to come later.

Some query examples:

These are parsed into objects, slightly different depending on the format option.

// Order Query: '?order=id&order=-name'

// Where Query: '?where[name]=doug&where[color]=red'

// Paged Query with Filters & Order: '?where[status=2]&order=id&limit=10&offset=10'

Installation

$ npm i sequery

or

yarn add sequery

or whatever &shrug; it's on npm you probably know how to install packages

Usage

const sequery = require('sequery');

const querystring = 'where[status]=2&where[foo]=bar&order=id&order=-baz&limit=10&offset=10';
const defaults = { limit: 10 };
const opts = { format: 'knex' };

const { where, order, offset, limit } = sequery(querystring, defaults, opts);

outputs:

{
  where: {
    status: '2', // can't parse int for misc wheres
    foo: 'bar'
  },
  order: [
    {column: 'id', order: 'asc'},
    {column: 'baz', order: 'desc'}
  ],
  limit: 10, // limit & offset both parse the int
  offset: 10
}

There is also { format: 'sequelize' } which just changes the order results to suit Sequelize like this:

{ order: [['id', 'asc'], ['baz', 'desc']] }
0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago