data-sorcerer [WORK IN PROGRESS]
Query any data source using a common, fluent API
Description
data-sorcerer
provides a unified interface for accessing any data source. It allows you to build queries to data sources using a fluent API. Such queries can then be converted to data source-specific queries and then executed.
Because query operations and results have a unified interface, generic modules can be built on top of data-sorcerer
to query any type of data source type and work with the results of such queries.
How to install
npm i data-sorcerer
How to use
; //Create references to data sources;;; //Get products out of stock .filterproduct.unitsInStock == 0; //Get employee full names from a city .filteremployee.city == 'London' .mapemployee.firstName + ' ' + employee.lastName;// -> [ 'John Smith', 'Lara Croft', 'Henry Spencer' ] //Get orders where a discount has been applied and select the product name .filterorder.orderDetails.anydetail.discount > 0 .map;/* ->[ { orderId: 1, products: [ { name: 'Dishwasher', discount: 50 } ] }, { orderId: 4, products: [ { name: 'Chair', discount: 1.25 }, { name: 'Desk', discount: 23.05 } ] },]*/
Lazy evaluation
All queries are lazy-evaluated meaning that the query is only sent for execution when the data source is converted to an array using toArray()
, when the result of the operation is a value, or when the data source is iterated.
.filteremployee.city == 'London' .mapemployee.firstName + ' ' + employee.lastName;//londonEmployees is still a queryable data source, the query has not been sent for execution ; //Results are loaded .filterproduct.unitsInStock == 0 .any;// -> true
Expression trees
The TypeScript expressions in these queries have to be converted to expression trees before they can be analyzed. For that we use ts-expressions. If you are making use of TypeScript expressions, you must compile data-sorcerer
using the ts-expressions
transformer. For more details please visit the ts-expressions
page.