Here's an example of how to use Tulip's Connectors feature to connect to a SQL database.
To add a new SQL connector:
1- Go to the Connectors page by placing your cursor over Apps in the Menu Bar and choosing Connectors from the dropdown.
2- Click "Add Connector" in the top right of the screen, give your connector a name and select "SQL" as the connector type.
3- On the Environments tab of the new connector, select "Add Connection Details".
4- Fill in the appropriate details to connect to the database:
- Running On ("Cloud Connector Host" unless you have set up a different setting)
- SSL (yes or no)
5- Click the Test button to run a test signal. If it is successful, hit "Save".
6- Ensure that the connector host has access to the database (indicated by green "Online" label next to the server on the Connectors page)
Once you have successfully set up a new connector, you can now create connector functions to send or retrieve data from the external database. A connector function must be written in the relevant language of the target database.
To set up a new SQL connector function:
1- Click the "Add New Function" button on the Functions tab.
2- Name the new function (this allows you to pick the specific connector function in Triggers).
3. Configure the function Inputs and Outputs
In the example above:
- configuration (text)
SELECT subconfig_1, subconfig_2, subconfig_3 FROM webinar database
WHERE configuration = $configuration$
order by id desc
limit 1 ```
A function can have multiple inputs and outputs. You will need at least one input or output in order to send/receive data from a Tulip App.
- Click Add to add a new input or output
- Give the field a recognizable name
- Choose the data type (e.g. Text, Boolean, Integer, etc.)
4. Add a valid SQL statement into the Query field. Note that the input variable names should be wrapped in $. Example: $input$.
5. Test the function
- If the function has inputs, enter valid values
- Click "Test" in the top right.
- View test results or error messages in the Test Results section
6. In some cases, you may want to return multiple rows from a SQL table. To do this, check the box next to "Return Multiple Rows". This will return an array full of objects, where each object contains values from one row in the SQL table.
SELECT name, num from numbers where num > $number$
(in the example above, number is an input)
Then, when you add your inputs and click "Test", you should see all the expected rows returned under "Test Results".
These can be stored in a variable as an array full of objects in the Trigger Editor.
7- Press "Save" when you are finished.
NOTE: Inputs and Outputs cannot be changed after saving a function. This is to prevent disruptions to apps that may be using a connector function.
If you need to add new inputs/outputs, you can copy the function and make changes in the new function.
For more information on how to write some commonly used SQL functions, reference, "Common SQL Connector Functions."