caql-js-compiler

2020-02-15

caql-js-compiler

A CaQL compiler that converts queries into executable JavaScript.

caql-js-compiler

Compile CaQL queries into executable JavaScript.

Learn more: Calypso Query Language (CaQL) Specification.

Install

npm install caql-js-compiler

Example

var JSCompiler = require('caql-js-compiler');

var entries = [
  { name: 'Postini', founded_year: 1999, total_money_raised: '$0' },
  { name: 'Digg', founded_year: 2004, total_money_raised: '$45M' },
  { name: 'Airbnb', founded_year: 2007, total_money_raised: '$120M' },
  { name: 'TripIt', founded_year: 2006, total_money_raised: '$13.1M' },
  { name: 'Twitter', founded_year: 2006, total_money_raised: '$1.16B' },
  { name: 'Spotify', founded_year: 2006, total_money_raised: '$183M' },
  { name: 'Airbnb', founded_year: 2008, total_money_raised: '$776.4M' }
];

var compiler = new JSCompiler();

var query =   'select name, founded_year, total_money_raised as worth '
            + 'where founded_year >= 1999 and name not like "%air%" '
            + 'order by founded_year desc, name';

compiler
  .compile(query)
  .execute(entries)
  .forEach(function(result) {
    console.log(result);
  });

// Output:
//
//    { name: 'Spotify', founded_year: 2006, worth: '$183M' }
//    { name: 'TripIt', founded_year: 2006, worth: '$13.1M' }
//    { name: 'Twitter', founded_year: 2006, worth: '$1.16B' }
//    { name: 'Digg', founded_year: 2004, worth: '$45M' }
//    { name: 'Postini', founded_year: 1999, worth: '$0' }

License

MIT

以上是 caql-js-compiler 的使用教程帮助文档。


上一篇:json-stream
下一篇:calypso-query-decompiler
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部