npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sequelize-query

v1.0.4

Published

Sequelize query parser

Downloads

61

Readme

Sequelize Query Parser

npm version npm downloads

GitHub latest stable releases GitHub releases GitHub stars GitHub license

GitHub issues GitHub open issues GitHub closed issues

Simple, powerful, minimalist package to turn your Node.js with Sequelize RESTful APIs into Graph APIs.

// Pass `db` connection object which has `Sequelize.Op`
const queryParser = require("sequelize-query")(db);

getUsers = async req => {
    // Parse your API query
    let query = await queryParser.parse(req);

    // Pass to Sequelize model find...() functions
    return User.findAndCountAll(query);
};

Features and Syntax with examples

  • Request specific set of fields instead of fetching all the table columns
// fields=field01,field02...

// E.g: Get only id, name and email
?fields=id,name,email
  • GET collection request APIs pagination support by default (without you writing code for that)
?offset=0&limit=10
// NOTE: Max page size limit is set to 200
  • GET collection request APIs sorting and groupping by default.

Sorting

// Sort by id in ascending order
?sort_by=id.asc

// Sort by name in descending order
?sort_by=name.desc

Grouping

// Group by id
?group_by=id
  • Simple filter query operations on the request objects
// Query format is
// filedName=unaryOperator:value

// Get all entries where firstName is like Reza or Rezaul, etc
?firstName=like:Reza%

// Get all entries where id is greater than 2 and lastName is like Reza%
?firstName=like:Reza%&id=gt:1
  • Querying with sequelize JSON format
// Find where firstname is Twaha and id is 1 or firstName is Riajul and id is 2
?query={"or": [{"and": [{"firstName": "Twaha"}, {"id": 1}]}, {"and": [{"firstName": "Riajul"}, {"id": 2}]}]}
// NOTE: query maps your query object to `where=queryObj`
  • Fetch and Query on relational objects (tables)
// Get only those whose role is 'admin'
?include={"model": "UserRole", "as": "userRole", "include" : {"model": "Role", "as" : "role", "required": 1, "where": {"name": "admin"} }}

Operators

Just use sequelize format query in the API requests
substituting Sequelize operators with below keys.

gt: Op.gt,                      // gt (greater than) for Op.gt
gte: Op.gte,
lt: Op.lt,
lte: Op.lte,
ne: Op.ne,
eq: Op.eq,
not: Op.not,
like: Op.like,                  // LIKE '%hat'
notLike: Op.notLike,            // NOT LIKE '%hat'
regexp: Op.regexp,              // REGEXP/~ '^[h|a|t]' (MySQL/PG only)
notRegexp: Op.notRegexp,        // NOT REGEXP/!~ '^[h|a|t]' (MySQL/PG only)
and: Op.and,                    // AND (a = 5)
or: Op.or,                      // (a = 5 OR a = 6)
between: Op.between,            // BETWEEN 6 AND 10
notBetween: Op.notBetween,      // NOT BETWEEN 11 AND 15
in: Op.in,                      // IN [1, 2]
notIn: Op.notIn,                // NOT IN [1, 2]

Installation

npm i sequelize-query

Contributing

I really appreciate your help in any case.
Fixes, Improvements, Enhancements, Documentation.

To contribute, please create a pull request to develop branch.