Filter streams according to SIQL queries
Kosu is an implementation of SIQL in JavaScript, for filtering Node.JS-style streams.
It compiles SIQL queries to JavaScript functions, and wraps them in a duplex stream that filters its input according to the query provided.
A command-line tool is also provided which can filter streams of JSON according
to a query. It is intuitively named kosu
.
Available via npm:
$ npm install kosu
Or via git:
$ npm install git://github.com/deoxxa/kosu.git
NOTE: if you want the command-line tool as well, you'll want to add the -g
flag to your npm install
command.
$ kosu <query> [input]
The kosu
command requires at least a query argument. This argument is JSON,
so must be quoted/escaped according to your shell's rules. By default, kosu
will read from stdin:
$ cat log.json | kosu '{"condition":{"type":"eq","left":"x","right":5}}'
By supplying a second argument, you can tell kosu to read from a file instead:
$ kosu '{"condition":{"type":"eq","left":"x","right":5}}' ~/log.json
Easy as pie!
constructor
Constructs a new Kosu object based on a query.
new Kosu(query);
var kosu = new Kosu({
condition: {
type: "eq",
left: "x",
right: 1,
}
});
Arguments
- query - an object specifying a SIQL query
Also see example.js.
var Kosu = require("kosu");
var query = {
fields: {
x: true,
y: true,
},
condition: {type: "and", data: [
{type: "eq", left: "x", right: 3},
{type: "and", data: [
{type: "gt", left: "info.time", right: "2012-08-24T00:00:00.000Z"},
{type: "lt", left: "info.time", right: "2012-08-24T23:59:59.999Z"},
]},
]},
};
var kosu = new Kosu(query);
console.warn("compiled filter function:");
console.warn("");
console.warn(kosu.filter.toString());
console.warn("");
console.warn("matching data:");
console.warn("");
kosu.on("data", function(e) {
console.log(e);
});
kosu.write({x: 3, y: 6});
kosu.write({x: 3, y: 7, info: {time: "2012-08-24T10:00:00.000Z"}});
Output:
compiled filter function:
function anonymous(obj) {
return true && (obj && obj['x']) === 3 && (true && (obj && obj['info'] && obj['info']['time']) > '2012-08-24T00:00:00.000Z' && (obj && obj['info'] && obj['info']['time']) < '2012-08-24T23:59:59.999Z');
}
matching data:
{ x: 3, y: 7 }
3-clause BSD. A copy is included with the source.
- GitHub (deoxxa)
- Twitter (@deoxxa)
- Email (deoxxa@fknsrs.biz)