Skip to content

Latest commit

 

History

History
104 lines (78 loc) · 2.48 KB

querying-data.md

File metadata and controls

104 lines (78 loc) · 2.48 KB

Querying Data

In our posts template, let's say we want to display the ten most recent blog posts. We can do this with by adding the following parameter to our posts route:

export default Ember.Route.extend({
  model: function() {
    return this.store.query('post', { orderBy: { publishedAt: 'desc' }, limit: 10 });
  }
});

Alternatively we can directly modify the the assumed Firestore reference, learn more about what query options are available in the Firestore documentation:

export default Ember.Route.extend({
  model: function() {
    return this.store.query('post', { query: ref => ref.orderBy('publishedAt', 'desc').limit(10) });
  }
});

This is useful for more advanced use cases.

Getting realtime updates to our queries

Use the RealtimeRouteMixin to get updates to records in your query while your route is in view.

import RealtimeRouteMixin from 'emberfire/mixins/realtime-route';

export default Route.extend(RealtimeRouteMixin, {
  model: function() {
    return this.store.query('post', { orderBy: { publishedAt: 'desc' }, limit: 10 });
  }
});

Query Options

Firestore

TODO write about the options available

    filter?: {[key:string]:any},
    where?: WhereOp|WhereOp[],
    endAt?: BoundOp,
    endBefore?: BoundOp,
    startAt?: BoundOp,
    startAfter?: BoundOp,
    orderBy?: OrderOp,
    include?: string

Query

    query?: (CollectionReference) => (Query|CollectionReference), 
    limit?: number

QueryRecord

    doc?: (CollectionReference) => (Query|DocumentReference)

Realtime Database

    query?: (Reference) => Reference,
    filter?: {[key:string]:string|number|boolean|null},
    endAt?: BoundOp,
    equalTo?: BoundOp,
    limitToFirst?: number,
    limitToLast?: number,
    orderBy?: string|OrderBy,
    startAt?: BoundOp

Query

    limit?: number

Working with security rules

... TODO flush out

Continue reading

  1. Installation
  2. User Authentication
  3. Collect Analytics
  4. Saving and Retrieving Data
  5. Querying Data
  6. Relationships
  7. Security Rules
  8. Deploying to Firebase Hosting
  9. Fastboot support
  10. Deploying to Cloud Functions for Firebase