Studio enables you to use the database connectors to connect to your databases like, Elasticsearch, MongoDB, CouchDB, DynamoDB, Cloud DataStore, Firebase and so on.
Firebase is a highly durable database that can scale automatically to handle your application’s load.
Configuring Firebase connector
To add a Firebase DB connector, under Studio > Connectors, click (+) Connector and under Databases select the Firebase Realtime connector.
You need to first configure the database. Enter the Connector name which would be used when you need the connector in your apps and while adding queries. To connect a Firebase Connector you need to get the configuration details from the Firebase console.
Under the Firebase console, click on your Project settings, and choose the Service accounts tab. Select the Firebase Admin SDK icon, and click Generate new private key. A JSON file is then downloaded, from where you can copy the Private key and paste it into the Firebase Connector.
Optionally you can also create an account key from your Google Cloud Platform console. Select a project, and click Create Service Account and assign the “role” as Firebase Admin. Create a JSON Key type and download the file. Keep it handy for use for connector configuration.
Copy the URL from the Firebase Console > Realtime Database > Data. It is typically in the form of https://.firebaseio.com/
Copy it to the Connector configuration Firebase Database URL and the Private Key from the JSON File that you had downloaded.
Once these configurations are added, click Test Connection. If the authentication is successful you would get the response accordingly. Click Save to Finish configuration.
Adding queries to the Database connector
Now that you have configured the connector you will find it under the Connectors list. Now to fetch data or undertake any other action, click the Add query option available once your connection is ready. Firebase contains Documents which contain data as Key Value pairs that can have nested data to the extent required. You can then have various actions to be performed on these Documents/ Collections. You can use different types of actions to Query database, Insert document, Update Document, Append, and Delete document.
So click Add Query and create a query. Enter a Service name and select your query Action and click Run or press Ctrl + enter to run the query. The rows returned from the database are shown in the Response section.
You can also add dynamic values using the Variables. To add the variable, click Variables > +Add. Add the FieldName and select the Field type. Ensure that you select the field type that matches the column type of the table, so that the query works correctly. Add a Test Value to check the results before saving. You can also add a Default value or make it Mandatory. Add the Help text that would be shown with the field. Once you have entered the details, click Add Variable. The variable would be listed under Variables. You can make use of the variable in the query where you created the variable.
To use a variable inside a query, you simply need to put it into double Curly brackets. The Test value that you entered would be considered for fetching data. When using the connector queries the dynamic variables would have to be linked to the respective control for further run time functioning.
You can now view the queries that you saved for using in your apps later under your specific connector under Custom Database connectors.
Using Firebase connector
Query Firebase data
Now let us take a simple example to fetch the Data from Firebase database . A sample is shown in the illustration below.
Provide the Action and the Database Ref in case you want a specific one. Run it to verify the output. Once done Save the query. For detailed information on adding the Reference you can refer to this article here.
You can add Ordering of the data based on Child, Key, Value. Depending upon the type you choose the Limit Type, Limit Number, Equal to, Start At and End At. For example if you Order by Value, and set the Limit type as Limit to First, with Limit number as 1 as seen in the example below, only one matching record starting from First record would be selected.
To display data you can add a table grid control or even a JSON viewer control. Go to Bind Data> Connectors and configure the query.
So now when you take a preview of the respective form you would be able to see the data for the specific database.
You can set data in a document. In this case choose the action as Set Data. You can provide a Database ref if you want to use a specific one else you can keep it blank.
Note: It is recommended that you provide the Database Ref. Do not keep it blank. If you do not provide the database ref it will overwrite the existing data.
In this example you would be accepting the data from a form and adding it on the Click of your Action button. Hence you will configure the Connector from the Action Flow > Server Side actions and add the respective controls as Keywords. The Set Action query would be configured with the Dynamic Variables.
So now considering that you would accept the key and values from the form the Connector configuration fields would be as seen in the illustration below.
For more information on adding the queries with the relative path of the database, you can refer to this documentation.
So whenever you run your form and click to submit data, the action flow would be triggered and the Connector will enable you to Set data to your Firebase Database. You can use a popup or toast action to display the ID created or view it in a text control as seen in the example below.
After you take a preview and add data, you can see the records in the Firebase Console > Realtime Database.
You can also update and delete documents from the Database. The query would be as seen in the example below.
Add the Update Action. Pass the values as Keywords from the form to configure the connector’s fields.
So configure the Connector Fields with Dynamic Variables passed as Parameter.
Now whenever you run the form you can provide the Key and the value to update. Click to update action.
In case you want to see the updated data you can go to the Firebase Console > Realtime Database to check the data.
Append data to the list
You can also use the Firebase Connector query to Append data to a list. When appending data you can provide reference of the existing list to append the data.
Let us add a query to the connector first to append data to the list to the same Accessories3 key / list we added in the earlier examples.
Select the action as Append data to a list, provide the Database Ref , and the values to append as a dynamic value. It can be any type of data or even an array or an object.
For example, you can add a TextInput control to append the item to the list on click of the Action button. Add an action flow task that triggers the Connector action to Append data. You can configure the connector where you will pass the TextInput control’s value as input.
So when you take a preview you will note that the record is appended to the list.
If you check the Firebase Console > Realtime Database you can see the record is appended to the list.
You can also use the Delete Action to remove any of the items from the document. Only remember that you provide the Database Ref, else all the data would be deleted.