This is preview documentation for functionality that will be introduced in our next scheduled release. Information on this page is subject to change until this time.
Building a database connector with the Connector Builder differs slightly from building standard connectors - instead of defining API endpoints, we define database queries. As such, you'll notice some UI variations from our standard Connector Builder guidelines.
Currently, the following database types are supported:
Database connectors are authenticated with username
and password
over SSL (if available, otherwise with no SSL).
We recommend ensuring that the accounts used to authenticate instances of this connector are associated with 'least privilege' permissions (so if you only need to read data, ensure that read-only permissions are applied).
Please ensure that any Patchworks variables used in queries are escaped, where appropriate - variable values are substituted at run time as-is; they are not interpreted, sanitised, or escaped automatically. For more information please see Working with queries.
Once you've chosen to add a new connector and launched the Connector Builder, a basic details form is displayed. For a database connector, you must set the system type
field to database
. This prompts a database type
field below - for example:
When you go on to choose a database type
and save this page, you'll step through a setup wizard to complete your connector setup:
This is very similar to the endpoint setup wizard, but there are some notable differences. These are detailed below:
As noted above, to build a database connector you must choose to set the system type
field to database
. This prompts a database type
field:
For more information on the basic details page please see our general Connector Builder section.
Variables are added and used as normal - i.e. any variables defined here are available when you move on to set up authentication for your connector:
For more information on the variables page please see our general Connector Builder section.
An authentication method must be defined as normal however, for a database connector the DB user pass authentication method should be used:
Having confirmed this selection, the default setup is displayed:
Values for all required authentication variables shown here must be provided when a user adds an instance of this connector. With the default (recommended) setup this means that the following values are expected:
username
password
port
host
database
Unless you have a specific reason for changing this setup, you can simply save this tab and continue.
Details for this authentication method are available on our DB user pass page. For more information on the authentication page please see our general Connector Builder section.
The queries tab is only displayed when you add a database
type connector. This is where you define queries that can be used in process flows (via the connector shape):
The process of adding a query is very similar to that of adding endpoints - having chosen to add a new system query
, you step through a series of pages to provide a name and a direction; define any required variables, add the query itself, and set pagination options.
If you're familiar with adding endpoints, you will recognise some of these options however, the steps below show specific setup requirements for queries.
Any issues found with queries at runtime (e.g. syntax errors) are reported from the database (verbatim) in run logs.
This is preview documentation for functionality that will be introduced in our next scheduled release. Information on this page is subject to change until this time.
When writing queries for a database connector, you use standard query language for the database type. However, there are some Patchworks-specific conventions to consider when passing in data from a Patchworks source, and some best practice recommendations.
Currently, MySQL is supported but further database types will be added in due course.
Conventions for working with Patchworks data in queries are detailed in the sections below:
If you want to retrieve data based on given values that vary at runtime, you can define query variables
in the connector setup, and include these in your queries:
Query variables
work in the same way as endpoint variables - they can be used to pass static values into queries or pass dynamic values at runtime.
To reference these variables in queries, we use the standard variable syntax for Patchworks endpoint/query variables:
{{variableName}}
For example, if we always wanted to target a row where the id
column is set to 4
, we might use the query below:
But if we want the flexibility to vary the target id
number, we can use a query variable:
In this case, the value of our {{id_to_use}}
variable would be passed into the query at runtime - perhaps specified by a user via connector shape settings, or generated from a script.
When defining a query variable for your connector, setting it to be configurable by a user
means that the variable is exposed in connector shape settings when the query is used - for example:
If we follow through with our example:
...and assume the value received at runtime is 8
, the query would resolved as below:
We don't interpret or sanitise query variable values - these are passed into the query as-is. As such, you'll need to consider if a variable should be escaped with quotes - see the Variable placement & escaping section below.
It's likely that you'll likely need to reference data from an incoming Patchworks payload in queries - for example:
Here we are saying: take id
, firstname
, surname
, and amount
values from the incoming payload and insert them into id
, firstname
, lastname
, and amount
columns in the orders
table. The query breaks down as follows:
As can be seen in the example above, we use colon-syntax parameters to reference payload data fields:
:placeholder
At runtime, parameter placeholders are replaced with corresponding values from the incoming payload.
Data is interpreted and inserted into the query as necessary - replacements with this syntax are completely safe and escaped.
You can access nested payload fields using dot notation (like standard payload variables). For example:
Patchworks meta-variables can be referenced in queries using the standard meta-variable syntax:
[[meta.variableName]]
For example:
In this example, we select all columns (*
) in our products
table but only for rows where the category
column is set to a value that will be passed in via a meta-variable [[meta.our_category]]
at runtime.
Meta-variable values can be set in a script, or via a set variables shape. If we follow through with our example:
...and assume the value received at runtime is bags
, the query would resolved as below:
We don't interpret or sanitise query variable values - these are passed into the query as-is. As such, you'll need to consider if a variable should be escaped with quotes - see the Variable placement & escaping section.
Patchworks flow variables can be referenced in database queries using the standard flow variable syntax:
{{flow.variables.variableName}}
For example:
In this example, we select all columns (*
) in our products
table but only for rows where the quantity
column is set to a value that will be passed in via a flow variable {{flow.variables.our_quantity}}
at runtime.
Flow variable values can be set in process flow settings, via a script, or in a set variables shape. If we follow through with our example:
...and assume the value received at runtime is 0
, the query would resolved as below:
We don't interpret or sanitise query variable values - these are passed into the query as-is. As such, you'll need to consider if a variable should be escaped with quotes - see the Variable placement & escaping section.
Any combination of variables can be used in both SELECT
and WHERE
sides of a query. For example:
On the SELECT
side, we don't need to worry about using escape quotes for string/varchar columns because we're always referring to column names.
On the WHERE
side, you should ensure that escape quotes are specified for variables where appropriate. Variables are not interpreted, sanitised or escaped - values are replaced as-is.
If you don’t properly escape variables being passed into queries, your database may interpret unescaped user input as part of the query itself, rather than treating it as plain data. As such, it's possible that a rogue actor could manipulate queries by injecting malicious code into your variables. With this in mind, always ensure you're working with known, safe data.
Escape character syntax may vary between database protocols but the principle is always the same.
Query character limit. Most database types will have a maximum character limit for queries - for example, MySQL has a limit of 1024K characters. Keep this in mind if you're inserting large amounts of data and consider batching your updates as appropriate.
As noted above, to build a database connector, you must set the system type
field to database
. This prompts a database type
field below - for example:
Select your required database type from the dropdown field:
Add a name
for this query and choose the type of entity
that you're querying:
General details are added in the top panel, with query configuration in the tabs below:
In the top panel, set the direction of this query as appropriate - i.e. does it modify data (send
) or retrieve data (receive
)?
Move down to the authentication
tab and toggle the DB user pass
authentication method on
for this query:
If you want to add variables for inclusion in this query (so values can be provided at runtime and injected into queries), select the query variables
tab and add the required variables:
Select the query
tab to add your database query - for example:
If your query includes parameters for pagination (LIMIT
and OFFSET
), select the pagination
tab to define the required values to be passed in - for example:
When prompted, choose the DB user pass
authentication method, then enter your credentials and database details:
Specifies the table (orders
) into which the new row will be inserted.
Defines column names in the orders
table to receive values.
Defines placeholders for payload fields - these are replaced by actual values (from the payload) at runtime.
Complete other settings and save your changes. As soon as you save this page, the database connector setup wizard is launched.
The name
entered here is displayed to users when they configure a to use this connector and are looking for a query to apply. Click the create
button to confirm and access query configuration options.
For general information about these settings, please see our main - the same principles apply to both endpoints and queries.
For general information about these settings, please see our main - the same principles apply to both endpoints and queries.
For general information about these settings, please see our main - the same principles apply to both endpoints and queries.
For examples of how variables might be used, see . For general information about these settings, please see our main - the same principles apply to both endpoints and queries.
This is where you define your query using the required syntax for your database (in this case, it's MySQL). Syntax highlighting is included (verification is not currently available - any issues with queries will be ). Standard syntax is used for the database type however, there are some Patchworks conventions to consider - please see for more information.
Limit offset
is the most commonly used pagination method for databases. For general information on this topic please see our main - the same principles apply to both endpoints and queries.
Having created all your required queries, you can go on to add instances of this connector () in the :