Fire Query Gator
This module provides simple API for querying Firebase Realtime Database.
Table of contents
General info
This is a user and developer friendly facade for Firebase Realtime Database standard queries. It does as much as possible to utilize built in firebase queries mechanisms, however due to their limitations some heuristics are used in order to provide simple API for developer.
Performance Notice
⚠️ Queries Response Time: Althought as much as possible processing is delegated to the firebase backend some operations will require full read of the database. Please also remember that You should add indexes on columns that you plan to use in your queries.
Features
- Single column where query with sorting and pagination
- Multi column where query with sorting and pagination (order by is on different column than where)
Module Documentation
Initialization
const q = ;// tell on which database queries should performvar db = admin;q;// from now on one can issue queries// ...
Output Specification
Object {d: data, m: metadata} is returned for each of the execute() calls. Please see below for detailed specification of each field
Kind | Parameter | Type | Description |
---|---|---|---|
Output | d |
array |
Result records array |
Output | d[i].v |
object |
Actual data object returned as i-th record |
Output | d[i].k |
object |
Actual database key returned for i-th record |
Output | m.s |
integer |
Size of result records array |
Output | m.n |
string |
Next page starting element (to be used with start() function ) |
Single column where query with pagination
Performs query using the same column/property for filering
var reference = 'course/students'; // from where we make the searchvar column = 'nationality'; // create queryvar query = q; // narrow only to certain nationalityquery = query; // get 10 elements starting from START_ELEMENTquery = querystartSTART_ELEMNT; query;
Single column orderby query with pagination
Performs query using the same column/property for sorting
var reference = 'course/students'; // from where we make the searchvar column = 'nationality'; // create queryvar query = q; // order by nationalityquery = query; // get 10 elements starting from START_ELEMENTquery = querystartSTART_ELEMNT; query;
Multi column query
Performs query using the different columns/properties for sorting and filering
var reference = 'course/students'; // from where we make the search // create queryvar query = q; var columnSort = 'age';var columnWhere = 'city';// sort students by agequery = query; // get only students from Warsawquery = query; // get 10 elementsquery = querystartSTART_ELEMNT; query;
Contact
Created by maciej.grula@xcft