This addon is for making database seraches with filters when using a Firebase database. Emberfire
, the services linking Ember.JS to Google Firebase, was deprecated before a good method for filtered searches was written. This addon is intended to be used in Ember.JS applications that are implemented with Embefire
.
First, install the addon with the following command:
ember install https://github.com/TomHeatwole/ember-emberfire-find-query
Next, go to any controller or component controller where you wish to perform a find query. Add this line in your imports.
import FindQuery from 'ember-emberfire-find-query/mixins/find-query';
Edit the export statement at the beginning of the file to include the FindQuery
mixin. That should
look something like this:
export default Ember.Component.extend(FindQuery, {
After the addon is installed and the mixin is included in your controller or component, you will have access to the following functions.
The find-query mixin has six "specific" filter functions:
filterEqual(store, model, params, callback)
filterNotEqual(store, model, params, callback)
filterGreaterThan(store, model, params, callback)
filterLessThan(store, model, params, callback)
filterGreaterThanOrEqualTo(store, model, params, callback)
filterLessThanOrEqualTo(store, model, params, callback)
store
: This is the DS.store for your Ember app. Passthis.store
in a controller orthis.get('targetObject.store')
in a componentmodel
: The name of the model which you wish to find (string)params
: A map which maps the name of the attribute to the desired valuecallback
: The callback function is called after the search is complete- The callback function takes in an array of the "found" instances of the model as a parameter
If you wanted to search your database for users with the first name Tom, it might look something like this:
this.filterEqual(this.store, 'user', {'firstName': 'Tom'}, function(toms) {
// Do something with toms
});
If you wanted to search your database for blog posts with 500+ views and 30+ shares, it might look something like this:
this.filterGreaterThanOrEqualTo(this.store, 'post', {'views': 500, 'shares': 30}, function(posts) {
// Do something with posts
});
Additionally, if you want to apply multiple filters to the same search, you would use the filterCustom
function:
filterCustom(store, model, params, callback)
store
: the DS.store for your Ember app. Passthis.store
inside a controller orthis.get('targetObject.store')
in a componentmodel
: The name of the model which you wish to find (string)params
: A map which maps the name of the attribute to an ordered pair (array) containing the operator and the desired value- Format:
{attribute1: [operator1, value1], attribute2: [operator2, value2] ... }
- Operators:
'=='
,'!='
,'>'
,'<'
,'>='
, and'<='
- Format:
callback
: The callback function is called after the search is complete- The callback function takes in an array of the "found" instances of the model as a parameter
Say you run into a case where you want to search for blog posts with 500+ views, less than 50 dislikes, created by a user named user225. Your find query might look something like this:
this.filterCustom(this.store, 'post', {
'views': ['>=', 500],
'dislikes': ['<', 50],
'author': ['==', 'user225']
}, function(posts) {
// Do something with posts
});
=======
git clone
this repositorynpm install
bower install
ember serve
- Visit your app at http://localhost:4200.
npm test
(Runsember try:testall
to test your addon against multiple Ember versions)ember test
ember test --server
ember build
##For more information on using ember-cli, visit http://ember-cli.com/.