aaronpowell / db.js

db.js is a wrapper for IndexedDB to make it easier to work against
http://aaronpowell.github.com/db.js/
MIT License
818 stars 142 forks source link

Added possibility to filter with object. #93

Closed emilkje closed 8 years ago

emilkje commented 9 years ago

I found it confusing why the filter would not accept object as filter method. This is now fixed. It generates a function which returns true if record has all and match all properties on the filter object.

Updated README and added tests.

aaronpowell commented 9 years ago

I see this as adding more code to db.js to solve a problem that is already quite easy to solve in your own code - https://github.com/aaronpowell/db.js/blob/master/tests/specs/query.js#L209-L232 and if you combine it with an ES6 transpiler it gets even simpler:

db.query('people').filter(r => r.firstName == 'Aaron' && r.lastName == 'Powell')
emilkje commented 9 years ago

I think its a really common use case to filter the results on more than one attribute, and I found the function api a little verbose for my taste. I was however not aware that the ES6 compiler made the api more friendly in that regard. I just found myself writing a helper resource.getBy({prop: 'value'}) and thought it would be a nice addition to your library thats all.

brettz9 commented 8 years ago

My personal opinion is that this does make things more elegant, even with the ES6 syntax.

aaronpowell commented 8 years ago

Closing - very out of date.