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

subtract-query-filter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subtract-query-filter

Subtracting filters analytically.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

subtract-query-filter

CircleCI Coverage

Use case

You need to fetch a lot of data from a remote server (with a filter that is defined on client-side and executed on server-side).

You want to fetch additional data of the same type, but you do not want to load documents a second time.

You could now include something like { _id: { $nin: [ ... a lot of ids ] } } to your filter.

This package offers a different approach: You just have to subtract the previously used filter from your new one.

Example

You implemented a calender with a day- and a month-view. There are a lot of events each there (therefore its expensive to exclude already fetched ids from new queries).

The user navigates through the app:

Time span fetchedInternal queryQuery to server
02.01.{date: {$in: [02.01.]}{date: {$in: [02.01.]}
01.01. - 07.01.{date: {$gte: '01.01.', $lte: '07.01.'{date: {$gte: '01.01.', $lte: '07.01.', $nin: [02.01.]
04.01. - 10.01.{date: {$gte: '04.01.', $lte: '10.01.'{date: {$gt: '07.01.', $lte: '10.01.'}

When to use

All of this does only make since if you need to fetch a lot of data or really must reduce the transferred data to a minimum.

If you don't, you might want to just fetch that data a second time.

Requirements / Interface

export type FilterConstraint = {
    $in?: any[];
    $nin?: any[];
    $lt?: any;
    $gt?: any;
    $lte?: any;
    $gte?: any;
}

export interface Filter {
    [key: string]: FilterConstraint;
}

The operations are restricted to the above.

{ $eq: VAL } must be expressed as { $in: [ VAL ] }.

{ $ne: VAL } must be expressed as { $nin: [ VAL ] }.

So far, it is not possible to use query operators like $and, $or, $all etc...

How to use

Keywords

FAQs

Package last updated on 09 Oct 2018

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