Skip to content

Commit bf4f188

Browse files
Documenting the sql prop in Connect (#16574)
* Documenting the sql prop in Connect * Update components.mdx
1 parent 0b25133 commit bf4f188

File tree

2 files changed

+178
-1
lines changed

2 files changed

+178
-1
lines changed

docs-v2/pages/connect/components.mdx

Lines changed: 170 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,174 @@ curl -X POST https://api.pipedream.com/v1/connect/{project_id}/components/trigge
10131013
}
10141014
```
10151015

1016+
## Special Prop Types
1017+
1018+
### SQL Prop
1019+
1020+
The `sql` prop is a specialized prop type used for interacting with SQL databases. It enables developers to build applications that can:
1021+
1022+
- Execute custom SQL queries
1023+
- Introspect database schemas
1024+
- Support prepared statements
1025+
1026+
This prop type is used by these database actions:
1027+
1028+
- `postgresql-execute-custom-query`
1029+
- `snowflake-execute-sql-query`
1030+
- `mysql-execute-raw-query`
1031+
- `microsoft_sql_server-execute-raw-query`
1032+
- `azure_sql-execute-raw-query`
1033+
- `turso-execute-query`
1034+
1035+
<Callout type="warning">
1036+
The `sql` prop is only supported in the Pipedream server SDK and REST API, and is not currently supported in `connect-react`.
1037+
</Callout>
1038+
1039+
#### Configuration
1040+
1041+
When configuring these actions, you'll need to provide:
1042+
1043+
1. Database app type and auth (e.g., `postgresql` in this example)
1044+
2. A `sql` prop with the following structure:
1045+
1046+
```javascript
1047+
const configuredProps = {
1048+
postgresql: {
1049+
authProvisionId: "apn_xxxxxxx"
1050+
},
1051+
sql: {
1052+
auth: {
1053+
app: "postgresql" // Database type -- must match the app prop name
1054+
},
1055+
query: "select * from products limit 1",
1056+
params: [] // Optional array of parameters for prepared statements
1057+
}
1058+
}
1059+
```
1060+
1061+
#### Using prepared statements
1062+
1063+
You can use prepared statements by including placeholders in your query and providing the parameter values in the `params` array. Different database systems use different placeholder syntax:
1064+
1065+
- **PostgreSQL** uses `$1`, `$2`, `$3`, etc. for numbered parameters
1066+
- **Snowflake**, **MySQL, Azure SQL, Microsoft SQL Server, and Turso** use `?` for positional parameters
1067+
1068+
<Tabs items={['PostgreSQL example', 'MySQL example']}>
1069+
<Tabs.Tab>
1070+
```javascript
1071+
const configuredProps = {
1072+
postgresql: {
1073+
authProvisionId: "apn_xxxxxxx"
1074+
},
1075+
sql: {
1076+
auth: {
1077+
app: "postgresql"
1078+
},
1079+
query: "select * from products where name = $1 and price > $2 limit 1",
1080+
params: ["foo", 10.99] // Values to replace $1 and $2 placeholders
1081+
}
1082+
}
1083+
```
1084+
</Tabs.Tab>
1085+
<Tabs.Tab>
1086+
```javascript
1087+
const configuredProps = {
1088+
mysql: {
1089+
authProvisionId: "apn_xxxxxxx"
1090+
},
1091+
sql: {
1092+
auth: {
1093+
app: "mysql"
1094+
},
1095+
query: "select * from products where name = ? and price > ? limit 1",
1096+
params: ["foo", 10.99] // Values to replace the ? placeholders
1097+
}
1098+
}
1099+
```
1100+
</Tabs.Tab>
1101+
</Tabs>
1102+
1103+
1104+
<Callout type="info">
1105+
Using prepared statements helps prevent SQL injection attacks by separating the SQL command structure from the data values being used, and is strongly recommended.
1106+
</Callout>
1107+
1108+
#### Retrieving database schema information
1109+
1110+
By retrieving the database schema, developers can:
1111+
1112+
- Provide database structure to AI agents for accurate SQL generation
1113+
- Build native SQL editors with autocomplete for tables and columns
1114+
- Validate queries against the actual database schema before execution
1115+
1116+
You can call `configureComponent` on the `sql` prop to retrieve database schema information:
1117+
1118+
```javascript
1119+
const resp = await pd.configureComponent({
1120+
externalUserId: externalUserId,
1121+
propName: "sql",
1122+
componentId: {
1123+
key: "postgresql-execute-custom-query",
1124+
},
1125+
configuredProps: {
1126+
postgresql: {
1127+
authProvisionId: accountId
1128+
},
1129+
},
1130+
});
1131+
```
1132+
1133+
The response includes a `context.dbInfo` object containing detailed schema information for all tables in the database:
1134+
1135+
```json
1136+
{
1137+
"context": {
1138+
"dbInfo": {
1139+
"products": {
1140+
"metadata": {},
1141+
"schema": {
1142+
"id": {
1143+
"tableName": "products",
1144+
"columnName": "id",
1145+
"isNullable": "NO",
1146+
"dataType": "integer",
1147+
"columnDefault": "nextval('products_id_seq'::regclass)"
1148+
},
1149+
"name": {
1150+
"tableName": "products",
1151+
"columnName": "name",
1152+
"isNullable": "NO",
1153+
"dataType": "character varying",
1154+
"columnDefault": null
1155+
},
1156+
"description": {
1157+
"tableName": "products",
1158+
"columnName": "description",
1159+
"isNullable": "YES",
1160+
"dataType": "text",
1161+
"columnDefault": null
1162+
},
1163+
"price": {
1164+
"tableName": "products",
1165+
"columnName": "price",
1166+
"isNullable": "NO",
1167+
"dataType": "numeric",
1168+
"columnDefault": null
1169+
},
1170+
"created_at": {
1171+
"tableName": "products",
1172+
"columnName": "created_at",
1173+
"isNullable": "YES",
1174+
"dataType": "timestamp with time zone",
1175+
"columnDefault": "CURRENT_TIMESTAMP"
1176+
}
1177+
}
1178+
}
1179+
}
1180+
}
1181+
}
1182+
```
1183+
10161184
## Troubleshooting
10171185

10181186
### Referencing the app prop in configured props payload
@@ -1102,4 +1270,5 @@ The sources UI contains three tabs:
11021270

11031271
<Callout type="info">
11041272
This UI view is currently in beta and has some limitations. Some UI elements may appear unpolished, and the configuration tab has limited functionality.
1105-
</Callout>
1273+
</Callout>
1274+

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)