-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create query-sql-database.mjs (#12617)
* Create query-sql-database.mjs * versions * Update components/database/actions/query-sql-database/query-sql-database.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update package.json * Update query-sql-database.mjs * generic sql query action --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7b32893
commit fe3ac03
Showing
2 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
components/database/actions/query-sql-database/query-sql-database.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* eslint-disable no-unused-vars */ | ||
/* eslint-disable pipedream/props-label */ | ||
/* eslint-disable pipedream/props-description */ | ||
import postgresql from "../../../postgresql/postgresql.app.mjs"; | ||
import mysql from "../../../mysql/mysql.app.mjs"; | ||
import snowflake from "../../../snowflake/snowflake.app.mjs"; | ||
|
||
export default { | ||
name: "Query SQL Database", | ||
key: "database-query-sql-database", | ||
description: | ||
"Execute a SQL Query. See [our docs](https://pipedream.com/docs/databases/working-with-sql) to learn more about working with SQL in Pipedream.", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
database: { | ||
type: "app", | ||
app: "database", | ||
}, | ||
db_type: { | ||
label: "Database Type", | ||
type: "string", | ||
description: "Select the database type you need to query", | ||
options: [ | ||
{ | ||
label: "PostgreSQL", | ||
value: "postgresql", | ||
}, | ||
{ | ||
label: "MySQL", | ||
value: "mysql", | ||
}, | ||
{ | ||
label: "Snowflake", | ||
value: "snowflake", | ||
}, | ||
], | ||
default: "postgresql", | ||
reloadProps: true, | ||
}, | ||
postgresql: { | ||
...postgresql, | ||
hidden: true, | ||
}, | ||
mysql: { | ||
...mysql, | ||
hidden: true, | ||
}, | ||
snowflake: { | ||
...snowflake, | ||
hidden: true, | ||
}, | ||
sql: { | ||
type: "sql", | ||
auth: { | ||
app: "postgresql", | ||
}, | ||
hidden: true, | ||
}, | ||
}, | ||
async additionalProps(prev) { | ||
const db_type = this.db_type?.value || this.db_type; | ||
|
||
prev.snowflake.hidden = db_type !== "snowflake"; | ||
prev.mysql.hidden = db_type !== "mysql"; | ||
prev.postgresql.hidden = db_type !== "postgresql"; | ||
prev.sql.hidden = !db_type; | ||
|
||
prev.snowflake.disabled = db_type !== "snowflake"; | ||
prev.mysql.disabled = db_type !== "mysql"; | ||
prev.postgresql.disabled = db_type !== "postgresql"; | ||
|
||
prev.sql.disabled = !db_type; | ||
prev.sql.auth.app = db_type; | ||
|
||
return { | ||
sql: { | ||
type: "sql", | ||
auth: { | ||
app: db_type, | ||
}, | ||
label: "SQL Query", | ||
}, | ||
}; | ||
}, | ||
async run({ | ||
steps, $, | ||
}) { | ||
const db_type = this.db_type.value || this.db_type; | ||
const args = this[db_type].executeQueryAdapter(this.sql); | ||
const data = await this[db_type].executeQuery(args); | ||
$.export( | ||
"$summary", | ||
`Returned ${data.length} ${data.length === 1 | ||
? "row" | ||
: "rows"}`, | ||
); | ||
return data; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters