Git Product home page Git Product logo

firebase-sql's Introduction

Firebase SQL

The Firebase SQL library accepts standard SQL queries and executes them as corresponding Firebase queries.

import fbsql from "fbsql";

// async:
const codingBlogs = await fbsql(`select * from blogs where genre = "coding";`);

// or apply a listener:
fbsql(`select * from users where online = true;`, onlineUsers => {
  // handle realtime updates...
});

Installation

npm install --save fbsql

Wait, but why?

Fbsql was extracted from the Firestation desktop app's source code to make issue tracking easier.

This library may be useful for:

  • Developers who prefer SQL syntax to the Firebase API
  • Saving time writing complicated functions that could be achieved with a one line SQL statement
  • Improving code clarity:
// firebase-sql
const codingBlogs = await fbsql(`select * from blogs where genre = "coding";`);

// realtime db
const snapshot = await firebase
  .database()
  .ref("/blogs/")
  .orderByChild("genre")
  .equalTo("coding")
  .once("value");
const codingBlogs = snapshot.val();

// firestore
const doc = await firebase
  .firestore()
  .collection("blogs")
  .where("genre", "==", "coding")
  .get();
const codingBlogs = doc.data();

Setup

Wherever you initialize firebase:

import firebase from "firebase/app"; // import * as firebase from "firebase-admin";
import { configureFbsql } from "fbsql";

firebase.initializeApp({ your config... });
configureFbsql({ app: firebase });

If you run into errors saying app.database() is not a function, you may need to import firebase into the file causing the issue. import firebase from "firebase/app";

Configuration

You have multiple configuration options through the configureFbsql function:

import fbsql, { configureFbsql } from "fbsql";

// pass any combination of options
// below are the defaults
configureFbsql({
  app: null // your firebase app
  isFirestore: false, // use firestore instead of the realtime db?
  shouldCommitResults: true, // commit changes on inserts, updates, deletes?
  shouldExpandResults: false // return a more detailed res obj from queries?
});

firebase-sql's People

Contributors

joeroddy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

firebase-sql's Issues

Can run unit tests.

I'm trying look into to issues for firestore but I can't run unit tests

  1. dates in where clauses don't seem to work in firestation
  2. sub collection queries doesn't seem to work. select * from users.subcollection

Try to run jest tests. npm test and getting the following error for all firestore tests.

Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

      at mapper (node_modules/jest-jasmine2/build/queueRunner.js:25:45)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.