Plum Fuse

Simple Database Integration

« Prev Section Variables and Math

Now that we've gone through various modules, let's learn how to integrate data using the Data Integration modules. Before we begin using those modules, however, we should first learn how to create a data table.

NOTE: The data tables within Plum Fuse should only be used for prototype applications as there is no 100% guarantee that they will store your data. Also, the modules, Query Database, Insert Into Database, Update Database, and Delete Rows, should only be used for prototype applications as these modules relate to the data tables.

To ensure that your data is stored correctly, we recommend the use of the SOAP and REST webservice modules.

Constructing a Data Table

Adding Data Manually

When building an application, you may have noticed a “Configure” tab located to the top right of your screen.

Clicking on the “Configure” tab will open up 3 additional tabs: Settings, Data, and Audio. Click on the Data tab to open up a data table.

To create a new table, click on the New Table button.

Next, enter a name for your data table (for this example, we're naming it “table1”).

Once you've named your table, click on the Add a Row button to begin adding rows to your table.

For our example, we're going to create a bank account application, so for fieldname, enter firstname. For the value, enter “John”. Click on the ”+” button for “Add a new field”. For the second fieldname, enter lastname. For the value, enter “Smith”. Click on the ”+” button again for “Add a new field”. For the third fieldname, enter savings. For the value, enter “550”.

NOTE: When adding column names, there are certain limitations. It allows for alphanumeric starting with a letter and allows for underscores.

Next, click on the Save changes button to save what you had just entered. Note that clicking on the Save changes button will insert a row of data into your table.

To add an additional fieldname to this row in your data table, first click on the checkbox for this row and click on the ”+” button for “Add a new field”. For this fieldname, enter acctnum and enter “8142” as the value.

To add another row of data into your data table, click on the “Add a Row” button and enter information into each of the fieldnames that you had created. For our specific example, however, we're going to leave the savings field blank.

Click on the Save changes button to add this new fieldname to your data table.

NOTE: There is a limit of 1000 bytes per value when saving to a data table.

Sharing a Data Table

Once you have created a data table, you can choose to share this data table with other users.

To share your data table, first click on the Share/Upload drop-down menu with your mouse and click on “Share this table with users.”

This will open up a window to add users to share your table. Once you have entered a user to share your table with, click on the plus button to add the user.

After adding the user, you can select checkboxes on what privileges you want to give the user. Clicking on the “Write” checkbox will allow the user to be able to write to the data table. Clicking on the “Reshare” checkbox will allow the user to be able to reshare the data table with other users.

Once you have finished applying your settings for the user, click on “Apply Changes” to save your configurations.

Uploading CSV Data to a Data Table

To upload CSV data to a data table through an API, first we need to construct the CSV file using the correct format.

The format of the file should be:

column_1,column_2,column_3
123,456,789
other,data,values

Please keep in mind that for column names, there are certain limitations. Think of them like JavaScript variables: alphanumeric starting with a letter and allowing underscores.

Using the information from our example above, we would set up our file to be:

acctnum,firstname,lastname,savings
8142,John,Smith,550
3456,Jim,Rainor

Now that we have some actual data in our data table, let's proceed with creating an application to use this data.

Account Application

To go back to your application, click on the “Untitled Page 1” tab.

On your application page, drag out a Digits Input module and connect it to the Start module. In the textbox, enter the following text: “Please enter your account number.” Next, drag out a Query Database module to your workspace and connect it to your Digits Input module. For the “Select from” drop-down menu, select table1 as the database. For column, select acctnum. For operand, select digits as the variable.

From here, drag out a Reserve Variable module to your workspace and rename the variable as rowamount.

Then, drag out a Stack Properties module to your workspace and connect it to your Query Database module. For Variable, select rowamount. For Property, select # of rows from the drop-down menu. This will allow us to retrieve the number of rows that matched the query from our Query Database module.

Drag out a Branch on Number module to your workspace and connect it to your Stack Properties module. For your If variable, select rowamount. For Comp., click on the drop-down menu and select >. For Value, enter 0 into the textbox.

For the default node of your Branch on Number module, connect a Simple Prompt module to it and enter the following text in the textbox: “I'm sorry, that account is not in our database.” Next, connect an Exit App module to the Simple Prompt module to close off that branch.

For the “0” node of your Branch on Number module, drag out a Get Row from Stack module and connect it to the node. For the variables for your Get Row from Stack module, enter the following variables: firstname, lastname, savings. This will allow us to retrieve the values for these entries in our data table.

Next, drag out a Branch on String module and enter savings as the variable (Note: we're intentionally leaving the node with the empty string disconnected for now as we'll cover this in the next section). Then, drag a Multipart Prompt module and connect it to the default node of the Branch on String module. In the textbox, enter the following text: “Your name is”. Click the ”+” button to add a variable to your module and select firstname as your variable. Click the ”+” button to add another variable to your module and select lastname as your variable. Click the ”+” button to add a phrase and enter the following text: “and you have”. Click the ”+” button to add another variable to your module and select savings as the variable. Click on the ”+” button to add another phrase and enter the following text: “in your savings account.”

From this example, we first have the user enter some digits and query our data table, table1, to see if the digits entered by the user match what's in acctnum in the table. The Stack Properties module is used to capture the number of rows that match the query. The Branch on Number module is then used to compare if the rowamount is greater than 0. If the rowamount is not greater than 0 (meaning there were no matches to the query), we branch to the statement, “I'm sorry, that account is not in our database.” If the rowamount is greater than 0 (meaning that there was at least one match to our query), we branch to a Get Row from Stack module, where we add the variables: firstname, lastname, and savings. By using this module, we are able to incorporate firstname, lastname, and savings into our application and use the values associated with those entries in our data table. From here, we drag out a Branch on String module to our workspace and connect it to the bottom node of our Get Row from Stack module. In the Branch on String module, we use the variable, savings, and compare it to an empty string (more on this in the next section). If the string is not empty, we proceed to our Multipart Prompt module, which states the user's full name and the savings in the account.

Updating a Database

In the previous section, we had a Branch on String module that acted upon an empty string. If that string had returned as empty, we should allow the user to enter their savings and update our data table with that information.

For that node in our Branch on String module, drag out a Digits Input module and connect it to that node. In the textbox of the module, enter the following text: “Please enter the savings amount you want to put into your account.” Then, drag out a Multipart Prompt module to your workspace and connect it to your Digits Input module. In the phrase textbox of the Multipart Prompt module, enter the following text: “You have entered”. Click on the ”+” button to add a variable to your Multipart Prompt module and select digits2 as the variable. Click on the ”+” button again to add a phrase to your Multipart Prompt module and enter the following text in the textbox: “into your account.”

Next, drag out an Update Database module to your workspace and connect it to the node on your Multipart Prompt module. Select table1 as the data table from the drop-down menu. For Fieldname, select savings. For Value, click on the toggler to convert it to a variable and select digits2 as your variable. For column, select acctnum. For operand, click on the toggler to convert it to a variable and select digits as your variable. Finally, drag out an Exit App module to your workspace and connect it to your Update Database module.

From this example, we use a Digits Input module and connect it to the empty string node on your Branch on String module to allow the user to enter a savings amount. The Multipart Prompt module is used to state back to the user what they had entered for the savings amount. For the Update Database module, we update our table1 data table by entering the value for digits2 into our fieldname, savings, where acctnum equals digits.

Taking this a step further, if you recall, we had an entry in our data table for Jim Rainor, where the savings fieldname was left blank. So, if Jim Rainor were to call into our application, he would enter 3456 as his account number and since there is nothing in the savings fieldname, he would be prompted to enter a savings amount. After he enters a savings amount, the table, table1, has its savings fieldname updated with the value of that savings amount where acctnum equals 3456.

Simplifying the Account Application

At the end of our Account Application, you may have noticed at how large the application was due to the amount of modules. We can simplify our application by using the “No row to fetch” node on the Get Row from Stack, which would replace the Stack Properties module and the Branch on Number module.

So, building off of the application already in place, first click on the “X” button on the Stack Properties module and the Branch on Number module to delete them from your workspace. Next, connect the node from you Query Database module to the receptor on your Get Row from Stack module.

Here's a final look at the simplified application:

Deleting Table Rows

The Delete Rows module allows you to delete rows from a database from within your application. This module is particularly helpful when you want to delete multiple rows from your database and don't want to do it manually.

We're going to build a simple example that demonstrates how you can use this module to delete rows programmatically from within your application.

First, let's create a data table for our application to reference. Just for this example, we've created a data table, veggies, with the following parameters:

Now that we have our data table, let's create our application. First, drag a Multiple Choice module to your workspace and connect it to your Start module. In your Multiple Choice module, enter the following in the textbox: “Please enter a vegetable. For eggplant, enter 1. For tomato, enter 2. For cucumber, enter 3. For okra, enter 4. For broccoli, enter 5. For spinach, enter 6. For onion, enter 7.” Then, click on the plus button until you have 7 choices available for your module. For choice 1, enter “eggplant” in the textbox. For choice 2, enter “tomato” in the textbox. For choice 3, enter “cucumber” in the textbox. For choice 4, enter “okra” in the textbox. For choice 5, enter “broccoli” in the textbox. For choice 6, enter “spinach” in the textbox. For choice 7, enter “onion” in the textbox. Finally, for your Multiple Choice module, go into Menu Options and make sure the checkbox for “Set result to keyword” is selected.

Next, drag a Multipart Prompt module to your workspace and connect it to your Multiple Choice module. In the textbox, enter the following text: “You entered”. Then, click on the plus button to add a phrase/variable to the module and click on the toggler to convert it to a variable. Enter multChoice as the variable.

Then, drag out a Delete Rows module to your workspace and connect it to your Multipart Prompt module. For your Delete Rows module, select veggies as the database table. For column, select kind. For operator, select ”=” from the drop-down menu. For operand, click on the toggler to convert it a variable and enter multChoice as the variable. Finally, for your Delete Rows module, go into Menu Options and make sure “Return # rows deleted”. This would allow you to return a variable containing the number of rows that were deleted from your database.

Next, drag out a Multipart Prompt module to your workspace and connect it to your Delete Rows module. In the textbox, enter the following text: “You deleted”. Then, click on the plus button to add a phrase/variable to your module and click on the toggler to convert it to a variable. Select multChoice as the variable. Click on the plus button again to add a phrase to your module and enter the following text in the textbox: “from your table. You deleted”. Click on the plus button to add another phrase/variable to your module and click on the toggler to convert it to a variable. Select rowsDeleted as your variable. Then, click on the plus button once more to add a phrase to your module and enter the following text in the textbox: “rows.” Finally, to complete the application, drag a Hang Up or Exit module to your workspace and connect it to your Multipart Prompt module.

From this example, the user selects a vegetable out of 7 choices. The user then hears the selection from the Multipart Prompt module. From here, the application goes to the Delete Rows module, which deletes the specific rows relating to the user's choice. Finally, the application tells the user which row was deleted from the database and the number of rows that were deleted.

Next Section » Running Other Applications
tutorial/app_basics/dataintegration.txt · Last modified: 2013/08/15 12:54 by victor