Skip to content

mlaanderson/database-js-firebase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

database-js-firebase

Build Status

Database-js interface for Firebase

About

Database-js-firebase is a database-js wrapper around the Firebase database library. It creates a Promises wrapper around an SQL to Firebase (NoSQL) interpreter.

It significantly restricts the structure Firebase as well as the access to Firebase. Right now access is limited to email and password.

Data must be stored using Firebase's ref.push. SQL commands are limited to CREATE, SELECT, UPDATE, INSERT and DELETE. WHERE, GROUP BY, and LIMIT are all functional. INNER JOIN, LEFT JOIN and RIGHT JOIN work, OUTER JOIN is not supported. Aggregate functions COUNT and SUM are supported.

CREATEs do not create a table structure because Firebase does not need a table to exist in order to insert data.

While a SELECT command can return a JSON object for a given field, JSON values cannot be UPDATEd or INSERTed, or be part of a WHERE clause.

RunKit Demo

Install

npm install database-js-firebase

Usage

If your Firebase data is structured as:

"$uid": {
    "users": {
        "firebase-autogenerated-key": {
            "username": "dduck",
            "fullname": "Donald Duck",
            ...
        },
        "firebase-autogenerated-key": {
            "username": "mmouse",
            "fullname": "Mickey Mouse",
            ...
        },
        ...
    }
}

Then your access will be like:

var Database = require('database-js2');

(async () => {
    let connection, statement, rows;
    connection = new Database('database-js-firebase://[my_email]:[my_password]@[project_id]/[root_node_path]?apiKey=[API KEY]');
    
    try {
        statement = await connection.prepareStatement("SELECT * FROM users WHERE username = ?");
        rows = await statement.query('dduck');
        console.log(rows);
    } catch (error) {
        console.log(error);
    } finally {
        await connection.close();
    }
})();

License

MIT (c) mlaanderson

About

Database-js interface for Firebase

Resources

License

Stars

Watchers

Forks

Packages

No packages published