npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

firebase-easy-query

v1.0.1

Published

A little library to help access and execute simple quieryes to Firebase databases.

Downloads

1

Readme

What is firebase-easy-query

Firebase Easy Query (feq) is a small and simple library that goal simplify the traditional coding to manipulate Firebase database.

It's a proposal to try make easy and comprensible queries to Firebase.

Feq is thinked for beginners developers and small projects or simple developments.

Contents

Install

npm install firebase-easy-query --save

If you are developing with Google Cloud Functions sure you are using Node 8 engine.

Adding feq to your JS project.

const { feq, operator } = require("firebase-easy-query");

Instancing feq

Using a serviceAccountKey.json file

const serviceAccount = require("./serviceAccountKey.json");

const config = {
    credential: serviceAccount,
    databaseUrl: "https://your-firebase-db.firebaseio.com"
};

const db = new feq(config);

Specifying only the database name

const config = {
    databaseUrl: "https://your-firebase-db.firebaseio.com"
};

const db = new feq(config);

Using default credentials.

const db = new feq();

Setup firebase access config to instance using:

  • Firebase JSON file config.
  • initializeApp method.

Example

const serviceAccount = require("myServiceAccountKey.json");
const config = {
    credential: serviceAccount,
    databaseUrl: "https://my-firebase-database.firebaseio.com"
};

const db = new feq(config);

##Setting root node with SetRoot property

Use SetRoot property when you neeed setup a particular node as root.

db.SetRoot = '/my/Root/Path'

Important notes:

  • When you set value for root, all queries will be executed over this path.
  • If you don't set this property it use '/' as root or don't set a value.

Members

feq was wrote to use an intuitive syntax, to achieve it is use two single methods: On() and From().

On(string)

On() is a function that can use to create, delete, append or remove objects and single nodes over an custom or specific path.

Syntaxis

 db.On(path)

 db.On('/my/example/path')

Create([string], object)

Create a data set using a js object.

 let singleUserData = {
     fullName: "Victor Carbajal",
     age: 17,
     address: "Noth #98, CA"
 };

 db.On('/my/Single/Path').Create(singleUserData);

Create function has one overload that is useful to specify the firebase key node name:

 let singleUserData = {
     fullName: "Victor Carbajal",
     age: 17,
     address: "Noth #98, CA"
 };

 // in this case, it uses "customString" to named to dataset in singleUserData object.
 db.On('/my/Single/Path').Create('customString', singleUserData);

Append(object)

This function adds a new node with its value to an exists object

let myNode = {
	name: "Tom Smith",
    age: 32
};

db.On('/path/anyNode').Append(myNode);

// Or...

db.On('/path/anyNode').Append({ name: "Tom Smith", age: 32 });

##Rename(object) Re-sets the node name specified at the end part of path.

Mandatory object:

{ oldName: "oldOrOriginalValue", newName: "newValue" }
db.On(`/users/real`).Rename({ oldName: "user", newName: "user01" });

Update(object)

Updates the value of a node represent by the value of the On function parameter.

db.On(`/users/real/user01`).Update({ email: "[email protected]" });

From(string)

Provides a set of functions that allow to you set new items on existing data. Specify the path to access to data tree that you wish affect.

GetSnapshot()

This function returns a promise.

Retrieves an object that represents an typically Firebase snapshot under once('value') statement.

let GetSnapshot = async () => {
    let snapshot = await db.From('/alphabetic/Alpha').GetSnapshot();
    let values = snapshot.val();
    let key = snapshot.key;
}

GetValue()

This function returns a promise.

Retrieves the value or object contained in the snapshot.

This function would be equivalent to invoke val() method from Firebase snapshot.

let GetValue = async () => {
    let value = await db.From('/alphabetic/Alpha').GetValue();
}

Delete()

Deletes the path specified inside From function.

Internally this action sets a null value.

// deletea the full tree accesible by '/my/Single/Path' path.
db.From('/my/Single/Path').Delete();

Remove(key, [condition])

Remove the node in the tree data using the From(path) and the specific node name (key parameter).

To consider all nodes to find in object located in path you can use the character * (asterisk) as value for the key parameter.

Remove a node with a specific value, use the where object:

NOTE

The where object is NOT compatible with conditions object of Where member.

{
    where: {
        operator: operator.$eq,
        value: 'target-value'
    }
}

db.From(`/users/real`).Remove('*', {
    where: {
        operator: operators.$eq,
        value: true
    }
});

CopyTo(string)

This function creates a copy of data located in the path specified in From parameter, the new location will be that you set in the CopyTo function parameter.

db.From('/original/path').CopyTo('/my/New/Path');

MoveTo(string)

This function creates a copy from data in the specified path in From, then deletes the original data setting a null value.

db.From('/original/path').MoveTo('/my/New/Path');

From(string).SelectFor([...args])

Returns a set of objects whose values coincides with the key-names requested in SelectFor function.

To get all results from a snapshot, don't set a value for the args parameter of the SelectFor function.

From(string).Select(...args).Where(conditions)

Select: use this function to specify the properties or keys names (separated by commas) that you want retrieve.

To get all results from a snapshot, don't set a value for the args parameter of the Select function.

When you specify a set of names the process returns one or more (an array of) object with this properties.

If a property does not exists the default value in the returned object will be a empty string.

Select("name", "age", "address")

// This strings produce an object similar to
{
	name: any,
    age: any,
    address any
}

Retrieve a dataset using a object that contains property name to compare, operator and value.

let conditions = {
    where: {
        key: "name",
        operator: operator.$eq,
        value: "Richard"
    }
}

db.From('/users/user01').Select("name", "age", "address").Where(conditions);

Operators

Usage:

const { operator } = require("firebase-easy-query");
  • Use $eq for equals to
  • Use $gt for great than
  • Use $ge for greater-than or equals
  • Use $lt for less than
  • Use $le for less-than or equals