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

relational-reselect

v1.0.11

Published

A declarative way to express queries with reselect

Downloads

4

Readme

relational-reselect

Build Status Coverage Status Codacy Badge npm bundle size NPM npm

With its decarative style, this library aims to facilitate creation of complex selectors on a normalized store that imposes to perform joins, lookups, relationships, or whatever you call it !

import { createSelector } from 'reselect';
import Query from 'relational-reselect';

// my selectors
const a = createSelector(
  aSelector,
  aFn,
);
const b = createSelector(
  bSelector,
  bFn,
);
const c = createSelector(
  cSelector,
  cFn,
);

// define my query
const myQuery = new Query()
  .from(a, 'a')
  .leftJoin(b, 'b')
  .on(row => row.getIn(['a', 'id']) === row.getIn(['b', 'aRef']))
  .leftJoin(c, 'c')
  .on(row => row.getIn(['c', 'id']) >= row.getIn(['a', 'cId']));

// get generated selector
const mySelector = myQuery.get();

// or directly run it
const myData = myQuery.run(state);

other examples are available on dedicated CodeSandbox

Install

npm install --save relational-reselect

How to write a query ?

State Machine diagram

API

Query bloc

new Query()

Create a new query

get(): Selector

generate selector for this query

run(state: State): Collection

run this query (= execute its selector) and return result

Select bloc

select(selectSpec: SpecificationForTuple): Select

Optional operation if you need to process data coming from From bloc.

From bloc

In this bloc, any dataSource can be a selector (a simple one or a reselect one) or another valid query if you need to nest them. Aliases are required for naming dataSources, except when you use except, intersect, and union joins

from(dataSource: DataSource, alias: string): From

Required operation.

Joins

Optional operation. You can join as much data sources as you want as long as you specify how to join them. Supported join types are :

  • innerJoin(dataSource: DataSource, alias: string): IncompleteJoin
  • leftJoin(dataSource: DataSource, alias: string): IncompleteJoin
  • rightJoin(dataSource: DataSource, alias: string): IncompleteJoin
  • fullJoin(dataSource: DataSource, alias: string): IncompleteJoin
  • except(dataSource: DataSource): CompleteJoin
  • intersect(dataSource: DataSource): CompleteJoin
  • union(dataSource: DataSource): CompleteJoin
  • cartesian(dataSource: DataSource, alias: string): CompleteJoin

Incomplete joins need to be completed with a on(specification: SpecificationForMatchingTuple): CompleteJoin

Where bloc

where(whereSpec: SpecificationForMatchingTuple): Where

Optional operation. This filter will be applied over data coming from From or Select (if exists) bloc

Ordering bloc

orderBy(orderBySpec: SpecificationForOrderingTuples): OrderBy

Optional operation. This sort will be applied over data coming from From, or Select (if exists), or Where (if exists) bloc

Grouping bloc

TODO !

Specification Types

type Tuple = Map<string, any>;
type SpecificationForTuple = (tuple: Tuple) => Tuple;
type SpecificationForMatchingTuple = (tuple: Tuple) => boolean;
type SpecificationForOrderingTuples = (left: Tuple, right: Tuple) => number;

Class Diagram

Class diagram