# db-api

A thin wrapper around the firebase npm module. Provides easy firebase authentication via environment variables, and exports basic database operations like GET, PUT, DEL. These are not firebase-specific, enabling applications that use db-api to easily switch databases. Also includes an interactive cli that provides a BASH-like interface for directly calling database operations.

## Setup
```npm install --production```
## Documentation
[See the API](API.md)

## Using mocked firebase server
If you wish to develop with a slow or absent Internet connection, you can use [firebase-server](https://www.npmjs.com/package/firebase-server), a mocked Firebase server that is run on your computer.

Simply do the following:

1. Add a line containing ```127.0.0.1 localhost.firebaseio.test``` to your [hosts file](https://en.wikipedia.org/wiki/Hosts_(file)#Location_in_the_file_system).

On OS X and Linux, the hosts file is located at ```/etc/hosts```.  On Windows, it is located at ```%SystemRoot%\System32\drivers\etc\hosts```.

2. Set the ```mockFirebase``` environment variable to true.

You can do this by adding ```mockFirebase=true``` to your leanonme-engine ```.env``` file or by running the command ```export mockFirebase=true```.




## Interactive CLI

### Start the REPL with:
```node repl.js <REL_PATH_TO_DOT_ENV_FILE>```

### Examples REPL Commands

#### Basic database operations:

```
DB> PUT meaning/of/life 42 
DB> GET meaning/of/life
DB> PUSH list/of/numbers 42
DB> MOVE meaning/of/life monty/python
DB> DEL monty/python
```
Note that no spaces are allowed in the path or the data.  
BAD:  
```DB> PUT knights/who {say: "ni"}```

#### Piping

Copy data    
```
DB> GET path/in/db | PUT new/path/in/db
```
Load object from the module.exports line of a js file, into the database.  
```
DB> REQUIRE data.js | UPDATE path/in/db
```

## Contributing to this API
### Setup
```npm install```
### Running tests
```npm test```
### Writing tests
Look at existing tests, and check out [MochaJS](https://mochajs.org)
and [ArgueJS](https://github.com/zvictor/ArgueJS)
### Generating API.md file from tests
```node_modules/mocha/bin/mocha --reporter markdown > API.md```