---
title: "How to Write a SQL Connector Function"
slug: "how-to-write-a-sql-connector-function-1"
updated: 2024-07-26T09:14:11Z
published: 2024-07-26T09:14:11Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://support.tulip.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure a SQL connector function

## 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](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/image%28703%29.png)

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

1. Configure the function Inputs and Outputs

![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Write%20a%20SQL%20Connector%20Function_156366200.png)

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 ```
```

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$
```

.

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

![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Write%20a%20SQL%20Connector%20Function_156366811.png)

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.

![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Write%20a%20SQL%20Connector%20Function_156367028.png)

**Query**

`SELECT name, num from numbers where num &gt; $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".

![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Write%20a%20SQL%20Connector%20Function_105139978.png)

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

- [How To Use The Output of Connector Functions In Apps](https://support.tulip.co/docs/how-to-use-outputs-from-connector-functions-in-apps)
- [An Overview of HTTP Connectors](https://support.tulip.co/docs/an-overview-of-http-connectors)

**Connectors**

**Connectors** enable real-time connectivity between your Tulip solution and a transactional system (e.g. an ERP). The output of a Connector Function can be used in Tulip Apps, Automations, and Functions.

- **HTTP Connectors** utilize HTTP API endpoints.
- **SQL Connectors** can enable connectivity with certain SQL databases.
- **MQTT Connectors** can connect to MQTT brokers for machine monitoring.

![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/connector.gif)

**Trigger**

**Triggers** are groups of logic that are tied to an app event, such as step open, timer, widget interaction, etc. App builders can add triggers to **widgets**, **machines**, **devices**, **apps**, and **steps**.

**Triggers** can contain **actions**, **transitions**, and **conditions**.

**Array**

**Arrays**are a Tulip Datatype. Arrays are a list of other variables. Every element in an array must be the same type.

Arrays are very useful when managing multiple values that represent the same information.

*ex. The measurements of 10 quality checks can be stored in an Array of Numbers, as opposed to 10 Number variables.*

**Object**

**Objects**are a Tulip Datatype. Objects represent an arbitrary grouping of attributes. Leveraging objects can simplify the process of working with complex data architectures. Often **Connector** **Functions** will return **Arrays** of **Objects**

*ex. My car object has 5 attributes, Color, Make, Model, # of wheels, # of seats.*

**Variable**

**Variables**are a location to store app information. Variables have a specific type that must match the contents they can store.

Variables are only accessible within a single application and are cleared when the app is restarted or completed.

**Trigger**

**Triggers** are groups of logic that are tied to an app event, such as step open, timer, widget interaction, etc. App builders can add triggers to **widgets**, **machines**, **devices**, **apps**, and **steps**.

**Triggers** can contain **actions**, **transitions**, and **conditions**.
