SQL Connector
Integrate Form.io forms with SQL databases (Microsoft SQL, MySQL, PostgreSQL) for efficient data management and direct handling of form submissions. Allows for also configuring a Custom SQL Rest API.
Last updated
Integrate Form.io forms with SQL databases (Microsoft SQL, MySQL, PostgreSQL) for efficient data management and direct handling of form submissions. Allows for also configuring a Custom SQL Rest API.
Last updated
If you are not using a Form.io project, check out Resquel. The following items are required to use the formio-sql server/container.
A Form.io Project on the Team Pro or Commercial Plan
A Node.js LTS Server, 9.x.x
or higher, or Docker
A MySQL/Microsoft SQL/PostgreSQL compatible server(s)
Instance of formio-server running versions (minimum as of 2021-02-11):
7.1.x
7.1.0-rc.2
Below is a minimum configuration. The library providing the underlying connection to the database is knex. The configuration placed inside
application.knex
is passed through.
1) Have API Server + SQL Databases already deployed and configured, or download the sql-connector-deployment.zip at the top of page.
2) Configure the settings in the .sqlconnectorrc and the .env files. Double check if all the settings will work for you configuration in the docker-compose.yml
3) Start the docker network by running the following command.
4) Create an API key in the project Settings -> Stage Settings -> API Keys, this will be used to set API_KEY in the .sqlconnectorrc
file.
5) In .sqlconnectorrc
configure LIVE_ENDPOINT with the current Project Endpoint.
6) Next we will need to restart the formio-sql Docker container.
7) Go to your developer portal application, and select the project that you'd like to integrate the SQL Connector with.
8) Configure your Form.io Project Settings, to have a SQL Connector Data Connection (Integrations > Data Connections, http(s)
scheme must be included on Host URL field).
8a) Below are the settings used sql-connector-deployment.zip.
SQL Connector Host URL
Type
MySQL
SQL Connector Username
foo
SQL Connector Password
bar
In this section we are going to be discussing how to configure a form to have the SQL Connector action, and configure the mappings to the columns in the specified table. For our demonstration of the connector we will be creating a Customer resource then attaching that resource to the SQL Connector action.
1) Create a resource form and call it Customer.
2) Then drag 2 Text Fields on to the Form. Label one as First Name, and label the second field as Email.
3) Now that we've created a Customer resource we need to configure the resource to use a SQL Connector action, and configure the mappings to the columns in the specified table.
4) Your SQL Connector should now be able to create, read, update, and delete records in the SQL database using the Form.io portal
This demonstration illustrates how to provide custom routing to your SQL Connector. Any SQL command you can think of you can create an endpoint to handle it.
1) Navigated to the stage Settings -> Stage Versions -> Import Template
2) Click Choose File, and import the sqlconnector-project.json located the connector directory in the sql-connector-deployment.zip file at the top of this page.
3) Click Import Project Template to current stage.
4) This will create a form called SQLConnector Routes click on this form, this form will be used to create custom API routes for our SQL database.
5) Once routes are created perform a Connector Refresh, see below for more details.
Query: The query object contains the query string parameters of the request URL. This allows you to access the values of the query string parameters in the request.
Body: The body object contains the data sent in the request body. This allows you to access the data sent in the request body, such as form data or JSON data.
Params: The params object contains the route parameters of the request URL. This allows you to access the values of the route parameters in the request.
Headers: The key-value pairs that are sent in the request and response of an HTTP request. They provide additional information about the request or response, such as the content type, language, encoding, and more. Headers can also be used to authenticate requests and control access to resources.
query.* Access URL Query Parameters
body.* Access Request Body Parameters
params.* Access URL Path Parameters named id
headers.* Access Request Headers
Whenever the connector configuration updates inside of the portal, the connector will need to be refreshed in order to pull in the changes. This can be done by making a GET /refresh to the SQL Connector. Accessing the refresh endpoint requires basic auth credentials to be provided. The form in the portal can be set up with a webhook action that has this endpoint as the target. With that set up, any time you modify the routes in your portal, your SQL Connector will automatically update.
Reasons to refresh the connector may include:
Modification to a SQL Connector action
Modification to data contained within the manual configuration form
The connector has a refresh route to allow for importing updates to the config (updates to the submissions in the portal forms). This is exposed as a GET /refresh endpoint.
1) Navigate to the SQLConnector Routes form actions, and select the Webhook Action.
2) See image below to see how to configure the Webhook Action. If using a deployed environment you will need to replace http://localhost:3002 with the hostname of the deployed environment as well as the Basic Auth credentials.