Junqi

What Does it Do?

It lets you take a JavaScript Array and query it.

Querying includes one or more steps of filtering, drill-down, synthesis, sorting and/or aggregation.

junqi's goal is to consolidate and expose multiple query grammars with a single backend. Initially, the objeq grammar will be supported.

Installation

Pre-built version of the parsers are already included, but if you'd like to build them yourself then you can do so by issuing the following command from the package's top-level directory:

npm install; npm run-script build

This will also install any development dependencies and run the nodeunit test suite.

Inclusion in Node.js

Assuming you have installed the junqi package into your project with npm, you can include it in a Node.js module with the following:

var junqi = require('junqi');

For access to a specific grammar:

var objeq = require('junqi').objeq;

Performing a First Query

Fire up the Node.js REPL and type the following into the console (minus comments):

// Import the objeq Grammar
var objeq = require('junqi').objeq;

// Create a data Array to be queried later
var data = [
  { name: 'Barbara', age: 25, gender: 'female' },
  { name: 'Ronald', age: 62, gender: 'male' },
  { name: 'Robert', age: 54, gender: 'male' },
  { name: 'Jessica', age: 48, gender: 'female' }
];

// This will compile a junqi query that filters
// only those Objects having a name property 
// starting with 'Ro' and then returns a string
// that combines name and age properties
var query = objeq("'^Ro' =~ name -> name + ' is ' + age + ' years old'");

// This performs the query against the 'data'
// Array and returns the result in 'res'
var res = query(data);

// --> res now contains:
//  [ 'Ronald is 62 years old',
//    'Robert is 54 years old' ]

Resources

For the latest releases, see the junqi GitHub Page

For more information about how to interact with the junqi library and its API, see the API Reference

For more information about the objeq grammar itself, see the objeq Grammar Reference

Credits and Acknowledgements

This module defines both a Lexer and Grammar that use the Jison Parser Generator

The objeq grammar was originally developed by Thomas Bradford and Stefano Rago for Agilo Software GmbH. The objeq library can be found at GitHub