Configuring DB connectors - CouchDB

Studio enables you to use the database connectors to connect to your NoSQL databases like DynamoDB, MongoDB, CouchDB, and so on.

CouchDB is an open-source document-oriented NoSQL database that uses multiple formats and protocols to store, transfer, and process its data

Configuring CouchDBconnector

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.

The most important part of the process is to provide the Connection strings. You can add the correct link or then provide the Connection string fields required for establishing a database connection.

For the CouchDB database you need to provide the following:

  • Host: Enter the correct Hostname
  • Port: Enter the Port name
  • Database: Enter the database name that contains all the collections
  • Username and Password: The Integration with CouchDB is supported using the username and password for authentication.
  • WhiteList IP: You can enable WhitelistIP to specify that DronaHQ is permitted to connect to the CouchDB database 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.

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 collection 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 or make it Mandatory. Add the Help text that would be shown with the field. You can also add any preset formula. 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.

Using CouchDB connector

Get Data

Now let us take a simple example to scan a CouchDB document and get data for the specific “_id” and display them in a tablegrid control. In this case, you simply need to select the collection, select the type of action as Get as you need to fetch the data from the collection. Provide the “_id” as a dynamic variable.

Add the query as seen above and run to verify the output. Once done Save the query.

You can then configure the query to display data in a control like the tablegrid control or a text label, and so on. Go to Bind Data> Connectors and configure the query. Here you can pass the respective “_id” by accepting from a text input control as keywords.

Find data

In this case, you simply need to select the type of action as Find as you need to find and fetch the data from the document. You can use MangoQuery to specify the Find action. To use these queries it is important to know the CouchDB syntax so that you can build your own custom queries for your applications based on the requirement.

In addition to these actions, you can also Insert data, update data, delete data from your documents by designing respective interactive forms and triggering the events from action flows or workflows.

Insert data

Using the DB Connector for CouchDB is similar to using it with other databases like MongoDB, DynamoDB, and so on. You can make use of the Queries to fetch data as well bind data such that you can undertake the insert, update, delete actions as well.

Now if you want to insert data into your collection you can use the Insert Action for the same with the respective values submitted from the form. You can fetch it from your form and assign the respective values using the dynamic variables.

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 add data to your CouchDB document.

addcouch data

Update Data

You can also update data from the collection using the Update action. Here you can also provide the Values as DynamicVariables to the respective keys.

It is important to remember that you would have to provide the respective values for the ‘_id’ and ‘_rev’ in the Value field of the Update Action.

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.

couchdb update

Similarly to delete data from your database you would have to choose Action as delete and provide the key to delete the item using the dynamic variable for the _id and _rev. It could be any scenario like say choosing a record from your table grid control and fetching the ID and adding the action flow to delete the record.