firebase-denormalizer
v2.0.0
Published
Automatic denormalized collections housekeeping and multi key filtering for Firebase Database
Downloads
5
Readme
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)