Studio enables you to use the database connectors to connect to your databases like Elasticsearch, MongoDB, CouchDB, DynamoDB, and so on.
Cloud Datastore is a highly durable database that can scale automatically to handle your application’s load.
Configuring Cloud Datastore connector
To add a DB connector, under Studio > Connectors, click (+) 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 build on top of your Cloud Datastore data, you need to make use of the Google Cloud Credentials for authentication. For detailed information on Service Account Authentication to get the private key, you can refer to this article here.
The Service Account should be created from the Google Cloud Storage > APIs and Services > Credentials. If the Service account is not created, then to create it select Service Account.
Enter all the details as required to create the Service account like Account details, description, granting access to projects, and granting user access
From the Service Account, you need to create a Key after you have added the details and given the necessary permissions. Create a JSON Key type and download the file. Keep it handy for use for connector configuration.
The most important part of the process for the Cloud Datastore is to provide the Private Key.
For the Cloud Datastore database you need to provide the connection string or the following parameters:
- Private Key: This is the private key associated with a Service Account with Datastore privileges.
- WhiteList IP: You can enable WhitelistIP to specify that DronaHQ is permitted to connect to the Cloud Datastore by white-list the specified IP address.
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. Cloud Datastore contains Entities. The entities are the data objects in Datastore. You can fetch an individual entity from a database using the entity’s key. You can also fetch one or more entities by using a query based on the entities’ keys or properties.
Here you will have a list of Actions that you can carry out like Get Entity by Key, Delete Entity by Key, Save Entity by key, and Query Datastore.
You can provide a name to the query using Enter a Service name. Add your query 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. Add a Test Value to check the results before saving. You can also add a Default value. 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.
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 use in your apps later under your specific connector under Custom Database connectors.
Using Cloud Datastore connector
Using the Connector for Cloud Datastore is similar to using it with other documents and collections like CouchDB, DynamoDB and so on.
Now if you want to Save the entity then you can specify the Kind and provide the entities as dynamic values. You can fetch it from your form and assign the respective values using the dynamic variables. You can keep the Key empty if you want to auto-generate the key. Cloud Datastore being a key-value pair you need to provide a new key name every time you are adding 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.
So whenever you run your form and click to submit data, the action flow would be triggered and the Connector will enable you to save data to your Cloud Datastore entity.
Now when you run the form you can add the Keyname and the data for first name and last name and submit the data. If you take a preview you can note that the data has been saved.
Get entity by key
Now let us take a simple example to fetch the entity details based on the Key. A sample is shown in the illustration below. In this case, you would be using the Get Entity by Key action.
Provide the namespace if you want to use a specific one else, it will take the default namespace. Add the query with the Kind to fetch data from and the Key name for which the data is to be fetched. Once done Save the query. Enter Kind. The Kind helps categorize the entity for the purpose of the queries.
Enter the Key value. In this case, we would be using a dynamic variable to fetch entities by key.
Now under Bind Data you can use this query to get data. Add a textinput control that accepts the Key and another table grid control that displays the record based on the key.
Provide the Keyname as the dynamic variable.
So now when you take a preview of the respective form you would be able to see the data as per the key entered. In this example we had the Key name as “Employee”, hence it fetched the First and Last Names accordingly which we had entered in the previous example for Save data.
Let us take an example to fetch data based on an GQL query and display it using a table grid. You can use the Action as Query Datastore. You can add a GQL query which is roughly mapped to the SQL query for the Kind to fetch the data and add filters or sort data as well.
Use this format for your queries:
SELECT * FROM `kind`
Refer to this documentation here to understand GQL to know how to build your queries.
You can then configure the connector accordingly and apply any transformation and formatting as required.
Configure the keys to display data in the tablegrid control.
Now if you take a preview you can see the data displayed in the table grid. In this example we have selected a simple query to select all data, however, you can make use of conditions or filters as well to fetch data.