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
npm install --save relational-reselectCreate a new query
generate selector for this query
run this query (= execute its selector) and return result
Optional operation if you need to process data coming from 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
Required operation.
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): IncompleteJoinleftJoin(dataSource: DataSource, alias: string): IncompleteJoinrightJoin(dataSource: DataSource, alias: string): IncompleteJoinfullJoin(dataSource: DataSource, alias: string): IncompleteJoinexcept(dataSource: DataSource): CompleteJoinintersect(dataSource: DataSource): CompleteJoinunion(dataSource: DataSource): CompleteJoincartesian(dataSource: DataSource, alias: string): CompleteJoin
Incomplete joins need to be completed with a on(specification: SpecificationForMatchingTuple): CompleteJoin
Optional operation. This filter will be applied over data coming from From or Select (if exists) bloc
Optional operation. This sort will be applied over data coming from From, or Select (if exists), or Where (if exists) bloc
TODO !
type Tuple = Map<string, any>;
type SpecificationForTuple = (tuple: Tuple) => Tuple;
type SpecificationForMatchingTuple = (tuple: Tuple) => boolean;
type SpecificationForOrderingTuples = (left: Tuple, right: Tuple) => number;

