tg-knex-query-resolver
Version:
TeselaGen's Knex based query resolver
22 lines (15 loc) • 702 B
JavaScript
module.exports = function combineQueries(qry1, qry2, joinOperator, opts){
if(qry1.__objectType !== 'query') throw new Error("First query is not a query type.");
if(qry2.__objectType !== 'query') throw new Error("Second query is not a query type.");
if(qry1.entity != qry2.entity) throw new Error("Queries are for different entities " + qry1.entity + " and " + qry2.entity);
if(joinOperator !== 'or') joinOperator = 'and';
var combinedFilters =
{
type: "group",
operator: joinOperator,
filters: [ ]
};
combinedFilters.filters = qry1.filters.concat(qry2.filters);
qry1.filters = [combinedFilters];
return qry1;
}