Skip to content

Examples Firebase Connection

Michael Anderson edited this page Dec 12, 2017 · 1 revision

The Firebase driver connects to a Firebase server. The Firebase driver does not support transactions.

Connection URL

firebase://username:password@project_id/root_node?apiKey=API_KEY

The root node is the path to the parent of the entries you define as tables.

The project ID and API key can be found in the Firebase console.

Usage

const Connection = require('database-js2').Connection;

var connection = new Connection('firebase://user@example.com:password@statesdemo/ewJviY6wboTKJ57A2dZkvq8kxYo1?apiKey=AIzaSyD1ypTmnJb_d8ZOyfc-KBMe0tw8owYCwjA')');

Select Some Data

var Connection = require('database-js2').Connection;

(async function() {
    let connection, statement, rows;
    connection = new Connection('firebase://user@example.com:password@statesdemo/ewJviY6wboTKJ57A2dZkvq8kxYo1?apiKey=AIzaSyD1ypTmnJb_d8ZOyfc-KBMe0tw8owYCwjA');

    try {
        statement = await connection.prepareStatement("SELECT * FROM states ORDER BY Ranking");
        rows = await statement.query();
        console.log(rows);
    } catch (error) {
        console.log(error);
    } finally {
        await connection.close();
    }
})();