0.0.1 • Published 7 years ago

minus-query v0.0.1

Weekly downloads
3
License
WTFPL
Repository
github
Last release
7 years ago

decode/encode query string prepended with sequelize or mongo/mongoose comparison operators

Sample (in express environment):

const minusQuery = requrie('minus-query')

app.use('/items', (req, res, next) => {
  const decoded = minusQuery.decode(req.query);
  model.find(decoded, {raw: true})
    .then(items => res.json(items))
    .catch(next)
})

In the example above the URL like: /items?eq-name=John&gte-age=30 would return all Johns who have their age greater or equal 30, by decoding the query parameters into where-expression like:

{
  name: {$eq: 'John'},
  age: {$gte: '30'}}
}