-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Queries and Filtering #76
Comments
I didn't realize you had to use the term "query" on a DS.findAll('user', {
search: 'Charles'
}); Actually, I've been wondering why there's documentation for the |
This is the first time anyone has questioned the query/filtering part of angular-data, so I'm glad for the opportunity to discuss and improve it. Ultimately my goal with // Whether the params format should change is up for discussion
var params = {
query: {
where: {
age: {
'>': 30
}
}
}
};
DS.findAll('user', params).then(function (users) {
assert.deepEqual(users, DS.filter('user', params));
});
Delegate to an adapter and make the query
Return the pending promise
Return (for example) Case 3 is tricky one. If the query has been made and completed, then the subset returned by the server has already been injected into data store. How do I immediately pull that same subset (now cached) out of the data store? If If there is a better option for handling case 3, let's discuss it. The current solution facilitates the following: app.controller('MyCtrl', function ($scope, DS) {
var params = {
query: {
where: {
age: {
'>': 30
}
}
}
};
DS.findAll('user', params);
// more verbose (and more control)
$scope.$watch(function () {
return DS.lastModified('user');
}, function () {
$scope.myUsers = DS.filter('user', params);
});
// less verbose
DS.bindAll($scope, 'myUsers', 'user', params);
}); Initially Technically, you can put anything you want into the Thoughts? |
The main reason i brought was that i was looking for a way to remove the query part of the url that is generated, so i started looking at the code. My api can't handle url?query={search: 'Charles'} i needs the format url?search='Charles'&limit=... and there did not seem to be any good way to do this. Even with custom queryTransform and custom filter, because these both handles the contents of the query object
These should both probably be passed the same arguments, so that a custom implementation for the specific api can be made where both the server and filter uses the same logic and returns the same subset of elements. And while you can do what @kentcdodds suggest to get the correct params sent to the server
this will not work with filter, since it will never be called when there are no query object |
Also while we are on the topic. the documentation for
But i can't find any references to this in the code so is the documentation wrong? And if not it seems strange to have value that is supported just by |
@kenborge Yes, "criteria" is wrong. I meant to put "where". I'm still thinking about the |
For now i am doing something like this to work around the problem
|
Perhaps flattening the params object a little by removing the need for nesting stuff under |
It does seem a bit redundant to me, unless there are plans to add other stuff then query, but i do not know what that would be, since orderBy and limit also are under query now. |
I think my original reason for adding it was to isolate the stuff angular-data needs from whatever else you might put in the params. |
I figured it was something like that. But does it not make sense that you would want access to whatever else you add to the params in the I think another point could be that if you don't use other params added when checking if the request has been done before or not(if it should be fetched from cache), then you can't tell if it's the same request since other params outside of query could have been changed. |
Yes, I'm realizing that now. |
@kenborge @kentcdodds What do you think? https://github.com/jmdobry/angular-data/blob/0.10.0/TRANSITION.md I'm thinking I might want to make DS.filter('post', { author: 'John' }); Would be interpreted by angular-data as: DS.filter('post' {
where: {
author: {
'==': 'John'
}
}
});
Of course, if you wanted other types of "where" statements you'd have to use the more verbose syntax: DS.filter('post' {
where: {
status: {
'in': ['flagged', 'deleted']
},
upVotes: {
'>': 100
}
}
}); |
Looks pretty good. And i like what you are saying about offering a "shortcut" to adding params without the |
The only thing that would change the |
👍 |
There is a problem with DS.findAll('resource', {offset: 10, limit: 10}) we will get requested items injected to data store and our query cached. But if we call the same code again, the |
Dang, I never ran into this issue because I always requested page 1 before requesting page 2. While you can get around this by passing the |
Hi.
There seems to be a requirement where queries either for find async methods or filtering for the filter sync methods require that you put params into a query object. Is this done because there are plans to add other possible params as well? If not it seems kind unnecessary, and it sets a few limitation, like many apis do not take a query param they just want the search params as normal url parameters.
Rolling your own queryTransform only allows you to modify the contents of the query object, not the query part it self so you can't remove it there. I guess the only option is to roll your own adapter, but that seems kind unnecessary when you can change most of the other behavior by just overriding the transform and filter methods.
The text was updated successfully, but these errors were encountered: