Skip to content

Commit 451611a

Browse files
Documenting the sql prop in Connect
1 parent 771e840 commit 451611a

File tree

2 files changed

+203
-1
lines changed

2 files changed

+203
-1
lines changed

docs-v2/pages/connect/components.mdx

Lines changed: 195 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,199 @@ 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+
#### Configuration
1036+
1037+
When configuring these actions, you'll need to provide:
1038+
1039+
1. Database app type and auth (e.g., `postgresql` in this example)
1040+
2. A `sql` prop with the following structure:
1041+
1042+
```javascript
1043+
const configuredProps = {
1044+
postgresql: {
1045+
authProvisionId: "apn_xxxxxxx""
1046+
},
1047+
sql: {
1048+
auth: {
1049+
app: "postgresql" // Database type -- must match the app prop name
1050+
},
1051+
query: "select * from products limit 1",
1052+
params: [] // Optional array of parameters for prepared statements
1053+
}
1054+
}
1055+
```
1056+
1057+
#### Using prepared statements
1058+
1059+
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:
1060+
1061+
- **PostgreSQL** uses `$1`, `$2`, `$3`, etc. for numbered parameters
1062+
- **Snowflake**, **MySQL, Azure SQL, Microsoft SQL Server, and Turso** use `?` for positional parameters
1063+
1064+
**PostgreSQL Example:**
1065+
```javascript
1066+
const configuredProps = {
1067+
postgresql: {
1068+
authProvisionId: process.env.ACCOUNT_ID
1069+
},
1070+
sql: {
1071+
auth: {
1072+
app: "postgresql"
1073+
},
1074+
query: "select * from products where name = $1 and price > $2 limit 1",
1075+
params: ["foo", 10.99] // Values to replace $1 and $2 placeholders
1076+
}
1077+
}
1078+
```
1079+
1080+
**MySQL Example:**
1081+
```javascript
1082+
const configuredProps = {
1083+
mysql: {
1084+
authProvisionId: process.env.ACCOUNT_ID
1085+
},
1086+
sql: {
1087+
auth: {
1088+
app: "mysql"
1089+
},
1090+
query: "select * from products where name = ? and price > ? limit 1",
1091+
params: ["foo", 10.99] // Values to replace the ? placeholders
1092+
}
1093+
}
1094+
```
1095+
1096+
<Callout type="info">
1097+
Using prepared statements helps prevent SQL injection attacks by separating the SQL command structure from the data values being used, and is strongly recommended.
1098+
</Callout>
1099+
1100+
#### Retrieving database schema information
1101+
1102+
By retrieving the database schema, developers can:
1103+
1104+
- Provide database structure to AI agents for accurate SQL generation
1105+
- Build native SQL editors with autocomplete for tables and columns
1106+
- Validate queries against the actual database schema before execution
1107+
1108+
You can call `configureComponent` on the `sql` prop to retrieve database schema information:
1109+
1110+
```javascript
1111+
const resp = await pd.configureComponent({
1112+
externalUserId: externalUserId,
1113+
propName: "sql",
1114+
componentId: {
1115+
key: "postgresql-execute-custom-query",
1116+
},
1117+
configuredProps: {
1118+
postgresql: {
1119+
authProvisionId: accountId
1120+
},
1121+
},
1122+
});
1123+
```
1124+
1125+
The response includes a `context.dbInfo` object containing detailed schema information for all tables in the database:
1126+
1127+
```json
1128+
{
1129+
"context": {
1130+
"dbInfo": {
1131+
"products": {
1132+
"metadata": {},
1133+
"schema": {
1134+
"id": {
1135+
"tableName": "products",
1136+
"columnName": "id",
1137+
"isNullable": "NO",
1138+
"dataType": "integer",
1139+
"columnDefault": "nextval('products_id_seq'::regclass)"
1140+
},
1141+
"name": {
1142+
"tableName": "products",
1143+
"columnName": "name",
1144+
"isNullable": "NO",
1145+
"dataType": "character varying",
1146+
"columnDefault": null
1147+
},
1148+
"description": {
1149+
"tableName": "products",
1150+
"columnName": "description",
1151+
"isNullable": "YES",
1152+
"dataType": "text",
1153+
"columnDefault": null
1154+
},
1155+
"price": {
1156+
"tableName": "products",
1157+
"columnName": "price",
1158+
"isNullable": "NO",
1159+
"dataType": "numeric",
1160+
"columnDefault": null
1161+
},
1162+
"created_at": {
1163+
"tableName": "products",
1164+
"columnName": "created_at",
1165+
"isNullable": "YES",
1166+
"dataType": "timestamp with time zone",
1167+
"columnDefault": "CURRENT_TIMESTAMP"
1168+
}
1169+
}
1170+
},
1171+
"orders": {
1172+
"metadata": {},
1173+
"schema": {
1174+
"id": {
1175+
"tableName": "orders",
1176+
"columnName": "id",
1177+
"isNullable": "NO",
1178+
"dataType": "integer",
1179+
"columnDefault": "nextval('orders_id_seq'::regclass)"
1180+
},
1181+
"user_id": {
1182+
"tableName": "orders",
1183+
"columnName": "user_id",
1184+
"isNullable": "NO",
1185+
"dataType": "integer",
1186+
"columnDefault": null
1187+
},
1188+
"total": {
1189+
"tableName": "orders",
1190+
"columnName": "total",
1191+
"isNullable": "NO",
1192+
"dataType": "numeric",
1193+
"columnDefault": null
1194+
},
1195+
"created_at": {
1196+
"tableName": "orders",
1197+
"columnName": "created_at",
1198+
"isNullable": "YES",
1199+
"dataType": "timestamp with time zone",
1200+
"columnDefault": "CURRENT_TIMESTAMP"
1201+
}
1202+
}
1203+
}
1204+
}
1205+
}
1206+
}
1207+
```
1208+
10161209
## Troubleshooting
10171210
10181211
### Referencing the app prop in configured props payload
@@ -1102,4 +1295,5 @@ The sources UI contains three tabs:
11021295
11031296
<Callout type="info">
11041297
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>
1298+
</Callout>
1299+

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)