Google Firebase and SQLTabs - sasha-alias/sqltabs GitHub Wiki

Google Firebase and SQLTabs

SQL Tabs supports queries to Google Cloud Firestore NoSQL database. So you can write your queries using javascript and view the results the similar way as it would be an ordinary table.

First let's connect to the Cloud Firestore. For that you need to get two things: a database URL and a service account file. Go to the Firebase Console, open the project and go to the Project Settings / Service accounts tab. You will find the database URL and the button for generating a new service account file in there.

So now you should be able to connect to your database just by entering the URL into connection string input and pointing to the service file in the appeared dialog:

After connection is established we can start writing queries. Let's first create a simple collection. Paste the following script into the SQLTabs and press Database -> Run Script or use the corresponding keyboard shortcut:

var citiesRef = collection("cities");

citiesRef.doc("SF").set({
    name: "San Francisco", state: "CA", country: "USA",
    capital: false, population: 860000,
    regions: ["west_coast", "norcal"] });
citiesRef.doc("LA").set({
    name: "Los Angeles", state: "CA", country: "USA",
    capital: false, population: 3900000,
    regions: ["west_coast", "socal"] });
citiesRef.doc("DC").set({
    name: "Washington, D.C.", state: null, country: "USA",
    capital: true, population: 680000,
    regions: ["east_coast"] });
citiesRef.doc("TOK").set({
    name: "Tokyo", state: null, country: "Japan",
    capital: true, population: 9000000,
    regions: ["kanto", "honshu"] });
citiesRef.doc("BJ").set({
    name: "Beijing", state: null, country: "China",
    capital: true, population: 21500000,
    regions: ["jingjinji", "hebei"] });

You may notice that this is the script similar to the one from the official documentation. We just don't need to refer to db object as SQLTabs uses always current database connection for scripts execution. Anyway, yet you will see nothing in the output window. In order to see the data you can use the select method of the collection class:

collection('cities').select();

This way you will see the documents IDs and the content in JSON format.

Also you can select the particular fields of the documents and apply some filtering:

collection("cities")
    .where('state', '==', 'CA')
    .select('name', 'country', 'state', 'population');

If you found a bug or have an idea for improvement, please don't hesitate to file an issue at github