Skip to content

Automatic denormalized collections housekeeping and multi key filtering for Firebase Database

Notifications You must be signed in to change notification settings

dsdenes/firebase-denormalizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)