Query Interface Discussion
Opened this issue · 4 comments
Alternative 1: Add a $query
method to $goKey
and a $key
method to $goQuery
var todos = $goKey('todos').$query(args);
var todos = $goQuery('todo's, args).$key('key')
Alternative 2: Add a $query
method to model
var todos = $goKey('todos').$sync();
todos.$query(args);
var stuff = todos.$key('users').$query({ thing: false }).$key('whatever');
I feel that the second option you've suggested provides the more intuitive interface. I'm slightly concerned it will impact the extensibility of the model!
After looking a how query is used with the todo example app I find it much cleaner to just use a goKey model and filter the data in that model rather than overwriting the model with a query model each time you wish to perform a different query.
$scope.todos = $goKey('todos').$sync();
<li ng-repeat="todo in todos | keyFilter | filter:{complete:false/true} | limitTo:5 | orderBy:'-$name'">
VS
$scope.showActive = function() {
$scope.todos = $goQuery('todos', {complete:false}, { limit: 5}).$sync();
};
$scope.showComplete = function() {
$scope.todos = $goQuery('todos', {complete:true}, {limit:5}).$sync();
};
$scope.showAll = function() {
$scope.todos = $goQuery('todos', {limit:5}).$sync();
};
<li ng-repeat="todo in todos | keyFilter">
Using $goQuery appears to be just a more complicated and foreign way (for angular devs) to filter/sort/limit data in comparison to filters which becomes super easy with #32
The difference is that Query will be faster and more flexible then Angular's filter/sort/limit that updates in realtime. The todo example doesn't do it justice.
Not sure how it can be more flexible when you can create your own filter for any specific purpose and chain filters together. I see the advantage of using query as a preliminary filter before applying the realtime angular filtering, but that can be done using angular filters too.
var data = $goKey('todos').$sync();
data = $filter('keyFilter')(data);
$scope.data = $filter('orderBy')($scope.data, '-$name');
All that has to be done to make this work like goQuery is to apply that filter each time the model changes, at the moment it is just being executed the once.