Skip to content

Commit df28463

Browse files
generic sql query action
1 parent 6468c67 commit df28463

File tree

2 files changed

+83
-12
lines changed

2 files changed

+83
-12
lines changed
Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,100 @@
1+
/* eslint-disable no-unused-vars */
2+
/* eslint-disable pipedream/props-label */
3+
/* eslint-disable pipedream/props-description */
14
import postgresql from "../../../postgresql/postgresql.app.mjs";
5+
import mysql from "../../../mysql/mysql.app.mjs";
6+
import snowflake from "../../../snowflake/snowflake.app.mjs";
27

38
export default {
49
name: "Query SQL Database",
510
key: "database-query-sql-database",
6-
description: "Execute a SQL Database. See [our docs](https://pipedream.com/docs/databases/working-with-sql) to learn more about working with SQL in Pipedream.",
11+
description:
12+
"Execute a SQL Query. See [our docs](https://pipedream.com/docs/databases/working-with-sql) to learn more about working with SQL in Pipedream.",
713
version: "0.0.1",
814
type: "action",
915
props: {
10-
postgresql,
11-
// eslint-disable-next-line pipedream/props-description
16+
database: {
17+
type: "app",
18+
app: "database",
19+
},
20+
db_type: {
21+
label: "Database Type",
22+
type: "string",
23+
description: "Select the database type you need to query",
24+
options: [
25+
{
26+
label: "PostgreSQL",
27+
value: "postgresql",
28+
},
29+
{
30+
label: "MySQL",
31+
value: "mysql",
32+
},
33+
{
34+
label: "Snowflake",
35+
value: "snowflake",
36+
},
37+
],
38+
default: "postgresql",
39+
reloadProps: true,
40+
},
41+
postgresql: {
42+
...postgresql,
43+
hidden: true,
44+
},
45+
mysql: {
46+
...mysql,
47+
hidden: true,
48+
},
49+
snowflake: {
50+
...snowflake,
51+
hidden: true,
52+
},
1253
sql: {
1354
type: "sql",
1455
auth: {
1556
app: "postgresql",
1657
},
17-
label: "PostreSQL Query",
58+
hidden: true,
1859
},
1960
},
20-
async run({ $ }) {
21-
const args = this.postgresql.executeQueryAdapter(this.sql);
22-
const data = await this.postgresql.executeQuery(args);
23-
const rowLabel = data.length === 1
24-
? "row"
25-
: "rows";
26-
$.export("$summary", `Returned ${data.length} ${rowLabel}`);
61+
async additionalProps(prev) {
62+
const db_type = this.db_type?.value || this.db_type;
63+
64+
prev.snowflake.hidden = db_type !== "snowflake";
65+
prev.mysql.hidden = db_type !== "mysql";
66+
prev.postgresql.hidden = db_type !== "postgresql";
67+
prev.sql.hidden = !db_type;
68+
69+
prev.snowflake.disabled = db_type !== "snowflake";
70+
prev.mysql.disabled = db_type !== "mysql";
71+
prev.postgresql.disabled = db_type !== "postgresql";
72+
73+
prev.sql.disabled = !db_type;
74+
prev.sql.auth.app = db_type;
75+
76+
return {
77+
sql: {
78+
type: "sql",
79+
auth: {
80+
app: db_type,
81+
},
82+
label: "SQL Query",
83+
},
84+
};
85+
},
86+
async run({
87+
steps, $,
88+
}) {
89+
const db_type = this.db_type.value || this.db_type;
90+
const args = this[db_type].executeQueryAdapter(this.sql);
91+
const data = await this[db_type].executeQuery(args);
92+
$.export(
93+
"$summary",
94+
`Returned ${data.length} ${data.length === 1
95+
? "row"
96+
: "rows"}`,
97+
);
2798
return data;
2899
},
29100
};

components/database/database.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

0 commit comments

Comments
 (0)