Easily convert your SQL database into a REST API, using the SQLConnector action from Form.io
This is a lightweight Express.js server that is able to wrap a SQL database, and expose functionality through pre-configured SQL Statements attached to a REST API. Using data from your Form.io project, routes are dynamically generated along with the SQL code to allow you to create forms in Form.io, and have the contents automatically inserted into your SQL Database using field mapping within the SQL Connector Form Action. Please go to https://form.io to learn more.
This library currently supports Microsoft SQL Server, MySQL, and PostgreSQL.
To get started with a new formio-sql server:
- Clone this repo
- Copy the contents of
- Update the contents of
DB_DATABASEto match your SQL instance.
- Select the
PORTyou want to run your
- Create a API Key on your Form.io Project for the
- Add your project domain to the
- Configure your Form.io Project settings, to have a SQL Connector Data Connection
- Configure a Form to have the SQL Connector action, and configure the mappings
- Start your formio-sql server, which will dynamically connect your server to your Form.io Forms, so all submissions will be stored in your connected database.
The following items are required to use the formio-sql server.
- A Form.io Project on the Team Pro or Commercial Plan
- A Node.js LTS Server, 4.x.x
- A MySQL/Microsoft SQL/PostgreSQL server (only one)
All the settings of this library are controlled via environment variables, which may be manually added to the start
SETTING=something npm start, or you can configure the
.env file. To configure the
.env file, copy
.env.example file to
.env and add your settings.
|PORT||3000||yes||The port this express server will run on.|
|TYPE||mysql||yes||The type of SQL syntax to use (mysql, mssql, postgresql).|
|DB_SERVER||localhost||yes||The SQL database host to use.|
|DB_PORT||no||The SQL database Port to use.|
|DB_USER||root||no||The SQL database user to use.|
|DB_PASSWORD||no||The SQL database password to use.|
|DB_DATABASE||formiosql||yes||The SQL database user to use.|
|FORMIO_KEY||yes||The API key for your Form.io Project.|
|FORMIO_PROJECT||yes||The Project _id for your Form.io Project.|
|AUTH_USERNAME||no||A Random username required to access this Server for Basic Auth, also used in the Form.io Project settings for SQL Connector.|
|AUTH_PASSWORD||no||A Random password required to access this Server for Basic Auth, also used in the Form.io Project settings for SQL Connector.|
|LEGACY||no||Override legacy support. Useful if you don't make a config.json file, and don't want to use defaults.json|
This library originally used a defaults.json file. That has been deprecated in favor of config.json. You can copy use config.json.example as a template, and add/remove any settings you want.
The db settings in config.json are used as a template, so any additional database settings will be passed on to the underlying libraries for extended functionality.
If you want don't want to create a config.json, it is recommended that you add the env variable LEGACY=false, to force the settings logic to use the expanded functionality.
The routes are primarily generated on Form.io, but can also be added manually. Adding custom routes to
will overwrite Form.io generated routes.
How it works
Upon running the formio-sql server, it will authenticate to your Form.io project and grab all the generated SQL Connector routes, so anytime the SQLConnector action is changed on Form.io, this server will need to be restarted to get the updated routes.
If you are not using a Form.io project, check out Resquel.
- The Form.io Team