MENU
    How to Write a SQL Connector Function
    • 26 Jul 2024
    • 3 Minutes to read
    • Contributors

    How to Write a SQL Connector Function


    Article summary

    How to Write a SQL Connector Function

    Use this guide to connect your Tulip App to a SQL Database.

    Here's an example of how to use Tulip's Connectors feature to connect to a SQL database.

    1- Click the "Add New Function" button on the Functions tab.

    image.png

    2- Name the new function (this allows you to pick the specific connector function in Triggers).

    1. Configure the function Inputs and Outputs

    In the example above:

    Inputs

    • configuration (text)

    Outputs

    • subconfig_1
    • subconfig_2
    • subconfig_3

    Query

    SELECT subconfig_1, subconfig_2, subconfig_3 FROM webinar database
    WHERE configuration = $configuration$
    order by id desc
    limit 1 ```
    Plain text

    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.)
    1. Add a valid SQL statement into the Query field. Note that the input variable names should be wrapped in $. Example:
    $input$
    Plain text

    .

    1. 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

    1. 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.

    Query

    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.

    If you need to add new inputs/outputs, you can copy the function and make changes in the new function.

    Further Reading


    Was this article helpful?