Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

feathers-query-filters

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feathers-query-filters

Adds support for special query string params used for filtering data

  • 1.5.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1K
increased by144.95%
Maintainers
2
Weekly downloads
 
Created
Source

feathers-query-filters

Adds support for special query string params used for filtering data in FeatherJS

NPM

Build Status

Installation

npm install feathers-query-filters --save

Getting Started

This is used internally in service adapters like Feathers MongoDB and Feathers NeDB.

Usage is like so:

var Proto = require('uberproto');
var filter = require('feathers-query-filters');

var CustomService = Proto.extend({
    init: function(name, options){
        // your custom initialization code
    },
    find: function(params, callback) {

        // Start with finding all, and limit when necessary.
        var query = this.db.find({});

        // Prepare the special query params.
        if (params.query) {
            var filters = filter(params.query);

            // $select uses a specific find syntax, so it has to come first.
            if (filters.$select) {
                query = this.db.find(params.query, filters.$select);
            } else {
                query = this.db.find(params.query);
            }

            // Handle $sort
            if (filters.$sort){
                query.sort(filters.$sort);
            }

            // Handle $limit
            if (filters.$limit){
                query.limit(filters.$limit);
            }

            // Handle $skip
            if (filters.$skip){
                query.skip(filters.$skip);
            }
        }

        // Execute the query
        query.exec(function(err, docs) {
            if (err) {
                return callback(err);
            }
            return callback(err, docs);
        });
    },
    setup: function(app) {
        // Called by feathers.configure()
        this.app = app;
        this.service = app.service.bind(app);
    }
});

module.exports = CustomService;

API

The following keywords are supported. They are pulled from the query object's conditions and returned so they can be mapped by each adapter in their own way.

$sort

$limit

$skip

$select

Changelog

1.0.1

  • Adding usage docs

1.0.0

  • Initial release.

License

MIT

Author

Eric Kryski

Keywords

FAQs

Package last updated on 22 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc