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-querystring-ex

v0.12.1

Published

Convert the request query string into sequelize compatible where and sort clauses.

Downloads

9

Readme

Node Sequelize query string

JavaScript Style Guide License

The aim of this module it to convert the request query string into sequelize compatible where and sort clauses.

The reason for the existence of this module is resumed in one single word: minimalist.

Features so far:

  • Convert filter attribute into where clauses
  • Multiple filter values (comma separated)
  • Nested properties
  • Supports almost every operator Tested operators: values: gt, gte, lt, lte, eq, ne, not, in, notIn, like, notLike, iLike, notILike arrays: overlap, contains, contained, between, notBetween
  • Convert sort attribute into order clause
  • Multiple sort values (comma separated)

Usage

Example in a hapijs compatible request handler:

  const sqs = require('sequelize-querystring')
  const ArticlesModel = require('./models/articles')

  // list articles
  exports.list = (req, res) => {
    return ArticlesModel.findAndCountAll({
      offset: req.query.offset || 0,
      limit: req.query.limit || 10,
      where: req.query.filter ? sqs.find(req.query.filter) : {},
      order: req.query.sort ? sqs.sort(req.query.sort) : []
    })
    .then((results) => {
      results.rows = results.rows.map((o) => { return o.get() })
      res(results)
    })
    .catch((err) => {
      log.error(err)
      res(err).code(500)
    })
  }

The compatible query string to filter and sort is like:

  http://localhost:3000/v1/articles?filter=author eq joaquim&sort=createdAt desc

The handler has pagination and by default it replies the first 10 items. To get the next page you could simply request:

  http://localhost:3000/v1/articles?filter=author eq joaquim&limit=10&offset=10

The filter is also compatible with multiple values operator 'or', 'in', 'notIn', 'overlap', 'contains', 'contained', 'between', 'notBetween' (Every values are separated with a space):

  http://localhost:3000/v1/articles?filter=date between 1995 2020

The compatible query string to multiple field filter with same value is like as:

http://localhost:3000/v1/articles?filter=firstName%7ClastName like %25John%25
http://localhost:3000/v1/articles?filter=firstName%26lastName like %25John%25

Contribute

If you want to contribute your're welcome. Keep in mind:

  • Test your fixes or improvements (npm test should pass)
  • Keep it simple