# firebase-query-gator

> Simple Query Gateway for Firebase

Latest version **1.0.20** (published 2020-04-02) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install firebase-query-gator
pnpm add firebase-query-gator
yarn add firebase-query-gator
bun add firebase-query-gator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.20 |
| Published | 2020-04-02 |
| First published | 2020-01-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 67.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maciej Grula |
| Maintainers | grulka |
| Keywords | firebase, query |

## Links

- npm: https://www.npmjs.com/package/firebase-query-gator
- Repository: https://github.com/alkeicam/firebase-query-gator
- Homepage: https://github.com/alkeicam/firebase-query-gator#readme
- Issues: https://github.com/alkeicam/firebase-query-gator/issues
- npm.io page: https://npm.io/package/firebase-query-gator

## Dependencies (1)

- [object-resolve-path](https://npm.io/package/object-resolve-path.md) 1.1

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 1.0.20 (latest) — 2020-04-02
- 1.0.19 — 2020-04-02
- 1.0.18 — 2020-02-01
- 1.0.17 — 2020-02-01
- 1.0.16 — 2020-02-01
- 1.0.15 — 2020-01-21

## README

# Fire Query Gator
> This module provides simple API for querying Firebase Realtime Database.

## Table of contents
* [General info](#general-info)
* [Performance Notice](#Performance-Notice)
* [Features](#Features)
* [Module Documentation](#Module-Documentation)  
    * [Initialization](#Initialization)  
    * [Output Specification](#Output-Specification)      
    * [Single column where query with pagination](#Single-column-where-query-with-pagination)   
    * [Single column orderby query with pagination](#Single-column-orderby-query-with-pagination)   
    * [Multi column query](#Multi-column-query)        
* [Contact](#contact)

## 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
> :warning: **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
```javascript
const q = require('firebase-query-gator');
// tell on which database queries should perform
var db = admin.database();
q.init(db);
// 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 
```javascript
var reference = 'course/students'; // from where we make the search
var column = 'nationality';

// create query
var query = q.query(reference); 
// narrow only to certain nationality
query = query.where(column, 'Cuban');

// get 10 elements starting from START_ELEMENT
query = query.limit(10).start(START_ELEMNT);

query.execute().then(result=>{
    // when resolves then operation was success
    // see operations documentation for details    
    var records = result.d;
    var ithRecord = records[i];
    var ithValue = ithRecord.v;
    var ithVKey = ithRecord.k;

    var dataLength = result.m.s;
});
```

### Single column orderby query with pagination
> Performs query using the same column/property for sorting  
```javascript
var reference = 'course/students'; // from where we make the search
var column = 'nationality';

// create query
var query = q.query(reference); 
// order by nationality
query = query.orderBy(column,query.DIRECTION.DESC);            
// get 10 elements starting from START_ELEMENT
query = query.limit(10).start(START_ELEMNT);

query.execute().then(result=>{
    // when resolves then operation was success
    // see operations documentation for details    
    var data = result.d;
    var dataLength = result.m.s;
});
```


### Multi column query
> Performs query using the different columns/properties for sorting and filering 
```javascript
var reference = 'course/students'; // from where we make the search

// create query
var query = q.query(reference); 
var columnSort = 'age';
var columnWhere = 'city';
// sort students by age
query = query.orderBy(columnSort,query.DIRECTION.ASC);

// get only students from Warsaw
query = query.where(columnWhere, 'Warsaw');

// get 10 elements
query = query.limit(10).start(START_ELEMNT);

query.execute().then(result=>{
    // when resolves then operation was success
    // see operations documentation for details    
    var data = result.d;
    var dataLength = result.m.s;
});
```
## Contact
Created by [maciej.grula@xcft](https://www.xcft.pl/)

---
_Source: https://npm.io/package/firebase-query-gator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
