Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions components/nile_database/actions/execute-query/execute-query.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import nile from "../../nile_database.app.mjs";

export default {
name: "Execute Query",
key: "nile_database-execute-query",
description: "Execute a custom PostgreSQL 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: {
nile,
// eslint-disable-next-line pipedream/props-description
sql: {
type: "sql",
auth: {
app: "nile",
},
label: "PostreSQL Query",
},
},
async run({ $ }) {
const args = this.nile.executeQueryAdapter(this.sql);
const data = await this.nile.executeQuery(args);
$.export("$summary", `Returned ${data.length} ${data.length === 1
? "row"
: "rows"}`);
return data;
},
};
91 changes: 86 additions & 5 deletions components/nile_database/nile_database.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,92 @@
import pg from "pg";

export default {
type: "app",
app: "nile_database",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
getClientConfiguration() {
const {
username,
password,
host,
port,
database,
} = this.$auth;

return {
user: username,
password,
host,
port,
database,
};
},
async _getClient() {
const config = this.getClientConfiguration();
const pool = new pg.Pool(config);
const client = await pool.connect();
return client;
},
async _endClient(client) {
return client.release();
},
async executeQuery(query) {
const client = await this._getClient();

try {
const { rows } = await client.query(query);
return rows;
} finally {
await this._endClient(client);
}
},
executeQueryAdapter(proxyArgs = {}) {
const {
query: text = "",
params: values = [],
} = proxyArgs;
return {
text,
values,
};
},
proxyAdapter(query) {
if (typeof query === "string") {
return {
query,
};
}

return {
query: query.text,
params: query.values,
};
},
async getSchema() {
const text = `
SELECT table_name AS "tableName",
column_name AS "columnName",
is_nullable AS "isNullable",
data_type AS "dataType",
column_default AS "columnDefault"
FROM information_schema.columns
WHERE table_schema NOT IN ('pg_catalog', 'information_schema', 'users', 'auth')
ORDER BY table_name,
ordinal_position
`;
const rows = await this.executeQuery({
text,
});
return rows.reduce((acc, row) => {
acc[row.tableName] ??= {
metadata: {},
schema: {},
};
acc[row.tableName].schema[row.columnName] = {
...row,
};
return acc;
}, {});
},
},
};
};
7 changes: 5 additions & 2 deletions components/nile_database/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/nile_database",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Nile Database Components",
"main": "nile_database.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"pg": "^8.13.0"
}
}
}
141 changes: 89 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading