Skip to content

Commit

Permalink
Initial attempt at query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Aug 25, 2014
1 parent 8ced517 commit 468cab7
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/components/services/queryBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var qb = angular.module("bawApp.services.queryBuilder", ["bawApp.configuration"]);

function Query() {

this.filter = {};
this.sort = {};
this.paging = {};

this.combinator = function combinator(type, arguments) {
this.graph[type] = [];

var that = this;
arguments.forEach(function(value, key) {
that.graph[key] = {};
value.call(that.graph[key]);
});

};

this.operator = function operator(operation, field, value) {
this.graph[field] = this.graph[field] || {};

this.graph[field][operation] = value;
}

}


Query.prototype.eq = function eq(field, value) {
this.operator("eq", field, value);
};

Query.prototype.and = function and(functions) {
this.combinator("and", functions);
};

Query.prototype.or = function or(functions) {
this.combinator("or", functions);
};

qb.factory("QueryBuilder", [function() {
return {
create: function() {
return new Query();
}
}
}]);

0 comments on commit 468cab7

Please sign in to comment.