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 toQuery
to the Workflow.Create a new Connection for the
Microsoft SQL Query
Node 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
Query
Property. 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
Execute
to see a preview of the data, click✓
to 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 Update
to insert the data we retrieved from theContacts
table into theNewContacts
table.Add
QuickMap
andMicrosoft SQL Table Update
, renamed toTableUpdate
to the Workflow.Create and assign a Connection on the
TableUpdate
using the same credentials as the one for theQuery
Node.Choose the
Insert into NewContacts
Node Sample forTableUpdate
.Connect
Query.ResultXml → QuickMap.Source
,QuickMap.Result → TableUpdate.TableXml
.In the QuickMap mapping (accessed from the
View/Change
link inQuickMap.Mapping
), clickTools → Mirror Map
to map all identically named fields.Map
Table → NewContacts
.Set a Map Expression on
company_name
toLEFT({company_name}, 15)
to trim the field to a size that is within the limit for the target table.Commit the changes by clicking
✓
.Back in the Workflow, set
TableUpdate.KeyFields
toid,email
and ensure that bothTableUpdate.AllowInsert
andTableUpdate.AllowUpdate
are checked.Connect
Query → QuickMap
andQuickMap → TableUpdate
.Run the Workflow to confirm that 10 rows have been inserted or updated in the
NewContacts
table.
Save your Workflow, then click Submit Exercise
to grade it.