oak-query

Iterable model for chaining query to simplify collection transformations and manipulations

Oak Query

Integration of iterable to make easier query over collections.

var Query = require("Oak-query");
 
var q = Query([5, 4, 3, 2, 1]);
 
console.info( q.first() ); // 5 
console.info( q.last() ); // 1 
console.info( q.skip(1).take(2).sum() ); // 7 
console.info( q.sort().first() ); // 1 

Based on iterator design, all query are also resolve at the evaluation, that make easier factorisations:

function filterCustumers(all){
  return Query(all).where(function(item){ return item.type === 3 });
}
 
function getCustumersRange(allstartcount){
  return filterCustumers(q).take(start, count);
}
 
function getLastCreatedCustumers(all){
  return filterCustumers(q).orderby("created").last();
}

Make less errors and easier to understand:

var pageSize = 10;
var customers = getCustumersRange(allEntities, pageSize * 10, pageSize).exec();
if(customers.any()){
  renderDetails(customers.orderby("name").toArray());
}
else{
  renderEmpty();
}