|
| 1 | +/* eslint-disable no-unused-vars */ |
| 2 | +/* eslint-disable pipedream/props-label */ |
| 3 | +/* eslint-disable pipedream/props-description */ |
1 | 4 | import postgresql from "../../../postgresql/postgresql.app.mjs";
|
| 5 | +import mysql from "../../../mysql/mysql.app.mjs"; |
| 6 | +import snowflake from "../../../snowflake/snowflake.app.mjs"; |
2 | 7 |
|
3 | 8 | export default {
|
4 | 9 | name: "Query SQL Database",
|
5 | 10 | 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.", |
7 | 13 | version: "0.0.1",
|
8 | 14 | type: "action",
|
9 | 15 | 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 | + }, |
12 | 53 | sql: {
|
13 | 54 | type: "sql",
|
14 | 55 | auth: {
|
15 | 56 | app: "postgresql",
|
16 | 57 | },
|
17 |
| - label: "PostreSQL Query", |
| 58 | + hidden: true, |
18 | 59 | },
|
19 | 60 | },
|
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 | + ); |
27 | 98 | return data;
|
28 | 99 | },
|
29 | 100 | };
|
0 commit comments