Skip to content

Neon PostgreSQL - New Components #16685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
70 changes: 70 additions & 0 deletions components/neon_postgres/actions/delete-rows/delete-rows.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import neon from "../../neon_postgres.app.mjs";

export default {
name: "Delete Row(s)",
key: "neon_postgres-delete-rows",
description: "Deletes a row or rows from a table. [See the documentation](https://node-postgres.com/features/queries)",
version: "0.0.1",
type: "action",
props: {
neon,
schema: {
propDefinition: [
neon,
"schema",
],
},
table: {
propDefinition: [
neon,
"table",
(c) => ({
schema: c.schema,
}),
],
},
column: {
propDefinition: [
neon,
"column",
(c) => ({
table: c.table,
schema: c.schema,
}),
],
label: "Lookup Column",
description: "Find row(s) by searching for a value in this column",
},
value: {
propDefinition: [
neon,
"value",
(c) => ({
table: c.table,
column: c.column,
schema: c.schema,
}),
],
},
},
async run({ $ }) {
const {
table,
schema,
column,
value,
} = this;

const errorMsg = "Row not deleted due to an error. ";

const rows = await this.neon.deleteRows(
schema,
table,
column,
value,
errorMsg,
);
$.export("$summary", `Deleted ${rows.length} rows from ${table}`);
return rows;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import neon from "../../neon_postgres.app.mjs";

export default {
key: "neon_postgres-execute-custom-query",
name: "Execute SQL 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: {
neon,
// eslint-disable-next-line pipedream/props-description
sql: {
type: "sql",
auth: {
app: "neon",
},
label: "PostgreSQL Query",
},
},
async run({ $ }) {
const args = this.neon.executeQueryAdapter(this.sql);
const data = await this.neon.executeQuery(args);
$.export("$summary", `Returned ${data.length} ${data.length === 1
? "row"
: "rows"}`);
return data;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import neon from "../../neon_postgres.app.mjs";

export default {
name: "Find Row With Custom Query",
key: "neon_postgres-find-row-custom-query",
description: "Finds a row in a table via a custom query. [See the documentation](https://node-postgres.com/features/queries)",
version: "0.0.1",
type: "action",
props: {
neon,
query: {
propDefinition: [
neon,
"query",
],
},
values: {
propDefinition: [
neon,
"values",
],
},
},
async run({ $ }) {
const {
query,
values = [],
} = this;

if (!Array.isArray(values)) {
throw new Error("No valid values provided. The values property must be an array.");
}

if (this.values) {
const numberOfValues = query?.match(/\$/g)?.length || 0;
if (values.length !== numberOfValues) {
throw new Error("The number of values provided does not match the number of values in the query.");
}
}

if (!query.toLowerCase().includes("select")) {
throw new Error("Need be a `SELECT` statement query. Read more about [SELECT queries here](https://www.w3schools.com/sql/sql_select.asp)");
}

const res = await this.neon.executeQuery({
text: query,
values,
errorMsg: "Query not executed due to an error. ",
});
$.export("$summary", "Successfully executed query");
return res;
},
};
73 changes: 73 additions & 0 deletions components/neon_postgres/actions/find-row/find-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import neon from "../../neon_postgres.app.mjs";

export default {
name: "Find Row",
key: "neon_postgres-find-row",
description: "Finds a row in a table via a lookup column. [See the documentation](https://node-postgres.com/features/queries)",
version: "0.0.1",
type: "action",
props: {
neon,
schema: {
propDefinition: [
neon,
"schema",
],
},
table: {
propDefinition: [
neon,
"table",
(c) => ({
schema: c.schema,
}),
],
},
column: {
propDefinition: [
neon,
"column",
(c) => ({
table: c.table,
schema: c.schema,
}),
],
label: "Lookup Column",
description: "Find row by searching for a value in this column. Returns first row found",
},
value: {
propDefinition: [
neon,
"value",
(c) => ({
table: c.table,
column: c.column,
schema: c.schema,
}),
],
},
},
async run({ $ }) {
const {
schema,
table,
column,
value,
} = this;

const errorMsg = "Row not found due to an error. ";

const res = await this.neon.findRowByValue(
schema,
table,
column,
value,
errorMsg,
);
const summary = res
? "Row found"
: "Row not found";
$.export("$summary", summary);
return res;
},
};
68 changes: 68 additions & 0 deletions components/neon_postgres/actions/insert-row/insert-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import neon from "../../neon_postgres.app.mjs";
import { parseRowValues } from "../../common/utils.mjs";

export default {
name: "Insert Row",
key: "neon_postgres-insert-row",
description: "Adds a new row. [See the documentation](https://node-postgres.com/features/queries)",
version: "0.0.1",
type: "action",
props: {
neon,
schema: {
propDefinition: [
neon,
"schema",
],
},
table: {
propDefinition: [
neon,
"table",
(c) => ({
schema: c.schema,
}),
],
},
rowValues: {
propDefinition: [
neon,
"rowValues",
],
description: "JSON representation of your table rows. Accept a single row (JSON Object) or multiple rows (JSON array). For example: `{ \"product_id\": 1, \"product_name\": \"Laptop Pro 15\", \"price\": 1200.50, \"stock_quantity\": 50, \"created_at\": \"2023-10-26T10:00:00Z\" }`",
},
},
async run({ $ }) {
const {
schema,
table,
rowValues,
} = this;
const results = [];
const parsedRowValues = parseRowValues(rowValues);
const parsedRowValuesArray = Array.isArray(parsedRowValues)
? parsedRowValues
: [
parsedRowValues,
];

const errorMsg = "New row(s) not inserted due to an error. ";

for (const row of parsedRowValuesArray) {
const columns = Object.keys(row);
const values = Object.values(row);
const res = await this.neon.insertRow(
schema,
table,
columns,
values,
errorMsg,
);
results.push(res);
}
$.export("$summary", `Successfully inserted ${results.length} row${results.length === 1
? ""
: "s"}`);
return results;
},
};
84 changes: 84 additions & 0 deletions components/neon_postgres/actions/update-row/update-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import neon from "../../neon_postgres.app.mjs";
import { parseRowValues } from "../../common/utils.mjs";

export default {
name: "Update Row",
key: "neon_postgres-update-row",
description: "Updates an existing row. [See the documentation](https://node-postgres.com/features/queries)",
version: "0.0.1",
type: "action",
props: {
neon,
schema: {
propDefinition: [
neon,
"schema",
],
},
table: {
propDefinition: [
neon,
"table",
(c) => ({
schema: c.schema,
}),
],
},
column: {
propDefinition: [
neon,
"column",
(c) => ({
table: c.table,
schema: c.schema,
}),
],
label: "Lookup Column",
description: "Find row to update by searching for a value in this column. Returns first row found",
},
value: {
propDefinition: [
neon,
"value",
(c) => ({
table: c.table,
column: c.column,
schema: c.schema,
}),
],
},
rowValues: {
propDefinition: [
neon,
"rowValues",
],
description: "JSON representation of your new table row values. For example: `{ \"product_name\": \"Laptop Pro 15\", \"price\": 1200.50, \"stock_quantity\": 50 }`",
},
},
async run({ $ }) {
const {
schema,
table,
column,
value,
rowValues,
} = this;

const parsedRowValues = parseRowValues(rowValues);
const errorMsg = "Row not updated due to an error. ";

const res = await this.neon.updateRow(
schema,
table,
column,
value,
parsedRowValues,
errorMsg,
);
const summary = res
? "Row updated"
: "Row not found";
$.export("$summary", summary);
return res;
},
};
Loading
Loading