09. Working with Databases
Many integrations require interaction with SQL databases, Flowgear provides two types of Connectors for this purpose.
- Query Connectors allow a query to be provided and the result set to be returned to the platform.
- Table Update Connectors allow for batch insert, update or upsert (insert or update) of rows using a user-specified composite custom key.
Native connectors are available for Microsoft SQL, MySQL, Oracle and PostgreSQL and generic connectors are offered for ODBC and OLEDB. See SQL Connectors for more information about the available connectors.
More about Table Update
When the AllowUpdate Property is enabled, the Table Update Nodes allow one or more fields to be set as key fields. For example, if you set the key field to id, then if a row contains an id that matches an existing row it will be updated rather than inserted.
You can also specify complex key fields - for example, you can specify id,email to match both the id and the email Property.
It's important to note that the fields you specify here do not need to be primary keys or indexed fields in the target database although performance will probably be better when they are.
Exercise 11: Working with Databases
In this exercise, we'll read contact information from one table in a database and then write those contacts to another table.
Add
Microsoft SQL Query, renamed toQueryto the Workflow.Create a new Connection for the
Microsoft SQL QueryNode and set these Properties:Server: CertificationTrainingDb.flowgear.net Database: CertificationTrainingDb UserId: CertificationTrainingDb Password: Training2019!Test and save the Connection. You will only be able to connect to this server from within your Flowgear Cloud environment.
Back on the Workflow, open the
QueryProperty. The list of available tables should display in the tree-view on the left-hand side.Set the query to
select top 10 * from Contacts.Test and save the Connection. You will only be able to connect to this server from within your Flowgear Cloud environment.
Click
Executeto see a preview of the data, click✓ Confirmto commit the Property value.Connect
Start.RunNow → Microsoft SQL Query.Run the Workflow to confirm the expected data is being returned.
We will now use
Microsoft SQL Table Updateto insert the data we retrieved from theContactstable into theNewContactstable.Add
QuickMapandMicrosoft SQL Table Update, renamed toTableUpdateto the Workflow.Create and assign a Connection on the
TableUpdateusing the same credentials as the one for theQueryNode.Choose the
Insert into NewContactsNode Sample forTableUpdate.Connect
Query.ResultXml → QuickMap.Source,QuickMap.Result → TableUpdate.TableXml.In the QuickMap mapping (accessed from the
View/Changelink inQuickMap.Mapping), clickTools → Smart Mapto map all identically named fields.Set a Map Expression on
company_nametoLEFT({company_name}, 15)to trim the field to a size that is within the limit for the target table.Commit the changes by clicking
✓ Confirm.Back in the Workflow, set
TableUpdate.KeyFieldstoid,emailand ensure that bothTableUpdate.AllowInsertandTableUpdate.AllowUpdateare checked.Connect
Query → QuickMapandQuickMap → TableUpdate.Run the Workflow to confirm that 10 rows have been inserted or updated in the
NewContactstable.
Save and run your Workflow, then click Submit Exercise to grade it.