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

@joinbox/loopback-component-relation-filter

v0.2.3

Published

Enables where query filters over related models via loopback api.

Downloads

11

Readme

loopback-component-relation-filter

Enables where query filters on related Loopback (3) models attached to a postgres data source.

The component currently has a bug when doing or queries. Since Loopback3 is will reach its EOL in December 2020 we will likely stop updating this package. Fixing its current limitations would require us to do a significant rewrite.

Purpose

By default, Loopback3 does not allow filtering over relations and related models. This component enables said feature by adding query pre-processing which loads the ids of the requested entities in one single query from the database.

Configuration

Enable/disable extended searching for all models in your component-config:

{
    "@joinbox/loopback-component-relation-filter": {
        "enabled": true,
        "rejectUnknownProperties": true,
        "preserveColumnCase": true
    }
}

Enable/disable searching for a specific model in your model-config.json (or also in your models definition file):

{
    "YourModel": {
        "options": {
            "relationFilter": {
                "enabled": false,
                "rejectUnknownProperties": true,
                "preserveColumnCase": false
            }
        }
    }
}

RejectUnknownProperties

If rejectUnknownProperties (default is true) is set to false the component will not throw an error during the normalization if the queried property/relation does not exist on the queried model. One can use this configuration value to ensure that legacy queries still work properly and do not fail.

PreserveColumnCase

If preserveColumnCase is set to false, column names are converted to lowercase when building the query. This option allows the user to make the filtering work with older, auto generated models (i.e. using automigrate/-update) where the column names were lowercased (e.g. property startDate will be converted to a column startdate).

Usage

The component uses Loopback's where query to create a big sql query against the database. Enable the filtering on your model and nest your where queries. The component supports a majority of the documented operators except near and regexp.

// e.g. load all books having an author which is employed by a certain publisher and is older than
// a certain age
const filter = {
    where: {
        author {
            employer: {
                identifier: 'fancy-publishing'
            },
            age: {
                gt: 20,
            },
        },
    },
};
const books = await Book.find(filter);

Caveats/Limitations

This package still has some serious limitations which are worth considering:

  • It is compatible with Loopback3 only.
  • The query building does not work correctly with or queries.
  • We do not support all documented operators namely: near and regexp (even though it is supported by postgres).
  • It only supports postgres databases.

Testing

Check the package.json to see how to execute tests:

  • all: npm test
  • unit: npm run test:unit
  • integration: npm run test:integration
  • watch tests during development: npm run test:watch (uses mocha's --watch option)
  • linting: npm run lint