Skip to content

Commit

Permalink
Create query-sql-database.mjs (#12617)
Browse files Browse the repository at this point in the history
* 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
dannyroosevelt and coderabbitai[bot] committed Jul 8, 2024
1 parent 7b32893 commit fe3ac03
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
100 changes: 100 additions & 0 deletions components/database/actions/query-sql-database/query-sql-database.mjs
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;
},
};
4 changes: 2 additions & 2 deletions components/database/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/database",
"version": "0.0.1",
"version": "0.1.1",
"description": "Pipedream Database Components",
"main": "database.app.mjs",
"keywords": [
Expand All @@ -12,4 +12,4 @@
"publishConfig": {
"access": "public"
}
}
}

0 comments on commit fe3ac03

Please sign in to comment.