Skip to content

Latest commit

 

History

History
68 lines (58 loc) · 1.41 KB

README.md

File metadata and controls

68 lines (58 loc) · 1.41 KB

CircleCI

Install

$ npm install firebase-denormalizer

Usage

import firebase from 'firebase';
firebase.initializeApp(<your config>);

import FirebaseDenormalizer from 'firebase-denormalizer';
const modelDenormalizer = FirebaseDenormalizer(firebase.database());
const dogs = modelDenormalizer('Dogs');

dogs.filterableProperty('type');
dogs.filterableProperty('kennel');

(async () => {
  await dogs.push({
    name: 'Lolly',
    type: 'wolfdog',
    Kennel: 'John Doe Kennel'
  });

  /*
   * Automatically creates and housekeeps you these denormalized collections:
   *
   * Dogs: {
   *   -KlzBG8yTrXZ5SG37mIa: {
   *     name: 'Lolly',
   *     type: 'wolfdog',
   *     Kennel: 'John Doe Kennel'
   *   }
   * }
   *
   * Dog-types: {
   *   'wolfdog': {
   *     -KlzBG8yTrXZ5SG37mIa: true
   *   }
   * }
   *
   * Dog-Kennels: {
   *   'johnDoeKennel': {
   *     -KlzBG8yTrXZ5SG37mIa: true
   *   }
   * }
   */


  /*
   * And from now, you can filter on multiple properties
   */
  await dogs.findValue({
    type: 'wolfdog',
    Kennel: 'John Doe Kennel',
    name: 'Lolly'
  });

})();

API

.findValue(<filter>) => Promise => collections

.find(<filter>) => Result EventEmitter

Result EventEmitter

.on('value', collections)