Database-js Interface for Firebase

1.2.2 · abandoned · verified Wed Apr 22

database-js-firebase is an adapter that provides an SQL-like interface to Google Firebase's NoSQL database, integrating with the `database-js` abstraction layer. Currently at version 1.2.2, the project appears to be abandoned, with the last code commits occurring in 2018 for this package and 2019 for its primary dependency, `database-js`. It translates a subset of SQL commands (SELECT, INSERT, UPDATE, DELETE, CREATE) into Firebase Realtime Database operations and provides Promises for asynchronous execution. Key differentiators include support for WHERE, GROUP BY, LIMIT, and INNER/LEFT/RIGHT JOINs, along with aggregate functions like COUNT and SUM. However, it imposes significant restrictions, such as requiring data storage via Firebase's `ref.push`, limiting authentication to email and password, and restricting interactions with JSON-typed fields. It does not create 'tables' in Firebase, as Firebase is schemaless. Due to its inactivity, it lacks compatibility with newer Firebase SDK versions or modern JavaScript features like ESM.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates establishing a connection to Firebase via the `database-js-firebase` driver, executing a parameterized SELECT query, and handling results or errors. Uses environment variables for sensitive credentials.

import { Database } from 'database-js';

(async () => {
    let connection, statement, rows;
    // Set these environment variables or replace with actual values
    const firebaseEmail = process.env.FIREBASE_EMAIL ?? 'your-email@example.com';
    const firebasePassword = process.env.FIREBASE_PASSWORD ?? 'your-password';
    const firebaseProjectId = process.env.FIREBASE_PROJECT_ID ?? 'your-project-id';
    const firebaseRootNodePath = process.env.FIREBASE_ROOT_NODE_PATH ?? 'your-root-node-path';
    const firebaseApiKey = process.env.FIREBASE_API_KEY ?? 'your-api-key';

    const connectionString = `database-js-firebase://${firebaseEmail}:${firebasePassword}@${firebaseProjectId}/${firebaseRootNodePath}?apiKey=${firebaseApiKey}`;
    connection = new Database(connectionString);
    
    try {
        console.log('Attempting to connect to Firebase Realtime Database...');
        // Example: Assume a 'users' collection with 'username' field
        statement = await connection.prepareStatement("SELECT * FROM users WHERE username = ?");
        rows = await statement.query('dduck');
        console.log('Query results:', rows);
    } catch (error) {
        console.error('An error occurred:', error);
    } finally {
        if (connection) {
            await connection.close();
            console.log('Connection closed.');
        }
    }
})();

view raw JSON →