--- title: "How to Write a SQL Connector Function" slug: "how-to-write-a-sql-connector-function" updated: 2024-08-28T10:48:48Z published: 2024-08-28T10:48:48Z canonical: "support.tulip.co/how-to-write-a-sql-connector-function" --- > ## 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. # 如何编写 SQL 连接器函数 ## 如何编写 SQL 连接器函数 *使用本指南将你的 Tulip 应用程序连接到 SQL 数据库。* 下面举例说明如何使用 Tulip 的连接器功能连接 SQL 数据库。 1- 点击功能选项卡上的 "添加新功能 "按钮。 ![image.png](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/image%28703%29.png) 2- 给新函数命名(这样就可以在触发器中选择特定的连接器函数)。 1. 配置函数的输入和输出 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Write%20a%20SQL%20Connector%20Function_156366200.png) 在上面的示例中 **输入** - 配置(文本) **输出** - 子配置_1 - 子配置 2 - 子配置 3 **查询** `SELECT subconfig_1, subconfig_2, subconfig_3 FROM webinar 数据库 WHERE configuration = $configuration$ order by id desc limit 1 ````` 一个函数可以有多个输入和输出。要从 Tulip 应用程序发送/接收数据,至少需要一个输入或输出。 - 点击*添加*,添加新的输入或输出 - 给字段起一个可识别的名称 - 选择数据类型(如文本、布尔、整数等) - 在查询字段中添加有效的 SQL 语句。请注意,输入变量名应以 $ 包装。例如 `$input$`. - 测试函数 - 如果函数有输入变量,请输入有效值 - 单击右上角的 "测试"。 - 在 "*测试结果*"部分查看测试结果或错误信息 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Write%20a%20SQL%20Connector%20Function_156366811.png) 1. 在某些情况下,您可能希望从 SQL 表中返回多条记录。为此,请选中 "返回多行 "旁边的复选框。这将返回一个包含对象的数组,其中每个对象都包含 SQL 表中一行的值。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Write%20a%20SQL%20Connector%20Function_156367028.png) **查询** `SELECT name, num from numbers where num > $number$` (在上面的示例中,*number*是输入值) 然后,添加输入并点击 "测试",就可以在 "测试结果 "下看到所有预期返回的行。 ![](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/How%20to%20Write%20a%20SQL%20Connector%20Function_105139978.png) 这些结果可以作为触发器编辑器中的对象数组存储在变量中。 7- 完成后按 "保存"。 如果需要添加新的输入/输出,可以复制函数并在新函数中进行更改。 ## 更多阅读 - [如何在应用程序中使用连接器函数的输出](https://support.tulip.co/docs/how-to-use-outputs-from-connector-functions-in-apps) - [HTTP 连接器概述](https://support.tulip.co/docs/an-overview-of-http-connectors)