Skip to content

Commit b89161c

Browse files
authored
Neon PostgreSQL - New Components (#16685)
* new components * add error * pnpm-lock.yaml * move sql related components to neon_postgres * pnpm-lock.yaml * pnpm-lock.yaml * remove sql related components from neon_api_keys * fix keys * updates * postgresql package version * updates * pnpm-lock.yaml
1 parent 610e27c commit b89161c

File tree

32 files changed

+1062
-194
lines changed

32 files changed

+1062
-194
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
3+
export default {
4+
name: "Delete Row(s)",
5+
key: "neon_postgres-delete-rows",
6+
description: "Deletes a row or rows from a table. [See the documentation](https://node-postgres.com/features/queries)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
neon,
11+
schema: {
12+
propDefinition: [
13+
neon,
14+
"schema",
15+
],
16+
},
17+
table: {
18+
propDefinition: [
19+
neon,
20+
"table",
21+
(c) => ({
22+
schema: c.schema,
23+
}),
24+
],
25+
},
26+
column: {
27+
propDefinition: [
28+
neon,
29+
"column",
30+
(c) => ({
31+
table: c.table,
32+
schema: c.schema,
33+
}),
34+
],
35+
label: "Lookup Column",
36+
description: "Find row(s) by searching for a value in this column",
37+
},
38+
value: {
39+
propDefinition: [
40+
neon,
41+
"value",
42+
(c) => ({
43+
table: c.table,
44+
column: c.column,
45+
schema: c.schema,
46+
}),
47+
],
48+
},
49+
},
50+
async run({ $ }) {
51+
const {
52+
table,
53+
schema,
54+
column,
55+
value,
56+
} = this;
57+
58+
const errorMsg = "Row not deleted due to an error. ";
59+
60+
const rows = await this.neon.deleteRows(
61+
schema,
62+
table,
63+
column,
64+
value,
65+
errorMsg,
66+
);
67+
$.export("$summary", `Deleted ${rows.length} rows from ${table}`);
68+
return rows;
69+
},
70+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
3+
export default {
4+
key: "neon_postgres-execute-custom-query",
5+
name: "Execute SQL Query",
6+
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.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
neon,
11+
// eslint-disable-next-line pipedream/props-description
12+
sql: {
13+
type: "sql",
14+
auth: {
15+
app: "neon",
16+
},
17+
label: "PostgreSQL Query",
18+
},
19+
},
20+
async run({ $ }) {
21+
const args = this.neon.executeQueryAdapter(this.sql);
22+
const data = await this.neon.executeQuery(args);
23+
$.export("$summary", `Returned ${data.length} ${data.length === 1
24+
? "row"
25+
: "rows"}`);
26+
return data;
27+
},
28+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
3+
export default {
4+
name: "Find Row With Custom Query",
5+
key: "neon_postgres-find-row-custom-query",
6+
description: "Finds a row in a table via a custom query. [See the documentation](https://node-postgres.com/features/queries)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
neon,
11+
query: {
12+
propDefinition: [
13+
neon,
14+
"query",
15+
],
16+
},
17+
values: {
18+
propDefinition: [
19+
neon,
20+
"values",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const {
26+
query,
27+
values = [],
28+
} = this;
29+
30+
if (!Array.isArray(values)) {
31+
throw new Error("No valid values provided. The values property must be an array.");
32+
}
33+
34+
if (this.values) {
35+
const numberOfValues = query?.match(/\$/g)?.length || 0;
36+
if (values.length !== numberOfValues) {
37+
throw new Error("The number of values provided does not match the number of values in the query.");
38+
}
39+
}
40+
41+
if (!query.toLowerCase().includes("select")) {
42+
throw new Error("Need be a `SELECT` statement query. Read more about [SELECT queries here](https://www.w3schools.com/sql/sql_select.asp)");
43+
}
44+
45+
const res = await this.neon.executeQuery({
46+
text: query,
47+
values,
48+
errorMsg: "Query not executed due to an error. ",
49+
});
50+
$.export("$summary", "Successfully executed query");
51+
return res;
52+
},
53+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
3+
export default {
4+
name: "Find Row",
5+
key: "neon_postgres-find-row",
6+
description: "Finds a row in a table via a lookup column. [See the documentation](https://node-postgres.com/features/queries)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
neon,
11+
schema: {
12+
propDefinition: [
13+
neon,
14+
"schema",
15+
],
16+
},
17+
table: {
18+
propDefinition: [
19+
neon,
20+
"table",
21+
(c) => ({
22+
schema: c.schema,
23+
}),
24+
],
25+
},
26+
column: {
27+
propDefinition: [
28+
neon,
29+
"column",
30+
(c) => ({
31+
table: c.table,
32+
schema: c.schema,
33+
}),
34+
],
35+
label: "Lookup Column",
36+
description: "Find row by searching for a value in this column. Returns first row found",
37+
},
38+
value: {
39+
propDefinition: [
40+
neon,
41+
"value",
42+
(c) => ({
43+
table: c.table,
44+
column: c.column,
45+
schema: c.schema,
46+
}),
47+
],
48+
},
49+
},
50+
async run({ $ }) {
51+
const {
52+
schema,
53+
table,
54+
column,
55+
value,
56+
} = this;
57+
58+
const errorMsg = "Row not found due to an error. ";
59+
60+
const res = await this.neon.findRowByValue(
61+
schema,
62+
table,
63+
column,
64+
value,
65+
errorMsg,
66+
);
67+
const summary = res
68+
? "Row found"
69+
: "Row not found";
70+
$.export("$summary", summary);
71+
return res;
72+
},
73+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
import { parseRowValues } from "../../common/utils.mjs";
3+
4+
export default {
5+
name: "Insert Row",
6+
key: "neon_postgres-insert-row",
7+
description: "Adds a new row. [See the documentation](https://node-postgres.com/features/queries)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
neon,
12+
schema: {
13+
propDefinition: [
14+
neon,
15+
"schema",
16+
],
17+
},
18+
table: {
19+
propDefinition: [
20+
neon,
21+
"table",
22+
(c) => ({
23+
schema: c.schema,
24+
}),
25+
],
26+
},
27+
rowValues: {
28+
propDefinition: [
29+
neon,
30+
"rowValues",
31+
],
32+
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\" }`",
33+
},
34+
},
35+
async run({ $ }) {
36+
const {
37+
schema,
38+
table,
39+
rowValues,
40+
} = this;
41+
const results = [];
42+
const parsedRowValues = parseRowValues(rowValues);
43+
const parsedRowValuesArray = Array.isArray(parsedRowValues)
44+
? parsedRowValues
45+
: [
46+
parsedRowValues,
47+
];
48+
49+
const errorMsg = "New row(s) not inserted due to an error. ";
50+
51+
for (const row of parsedRowValuesArray) {
52+
const columns = Object.keys(row);
53+
const values = Object.values(row);
54+
const res = await this.neon.insertRow(
55+
schema,
56+
table,
57+
columns,
58+
values,
59+
errorMsg,
60+
);
61+
results.push(res);
62+
}
63+
$.export("$summary", `Successfully inserted ${results.length} row${results.length === 1
64+
? ""
65+
: "s"}`);
66+
return results;
67+
},
68+
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
import { parseRowValues } from "../../common/utils.mjs";
3+
4+
export default {
5+
name: "Update Row",
6+
key: "neon_postgres-update-row",
7+
description: "Updates an existing row. [See the documentation](https://node-postgres.com/features/queries)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
neon,
12+
schema: {
13+
propDefinition: [
14+
neon,
15+
"schema",
16+
],
17+
},
18+
table: {
19+
propDefinition: [
20+
neon,
21+
"table",
22+
(c) => ({
23+
schema: c.schema,
24+
}),
25+
],
26+
},
27+
column: {
28+
propDefinition: [
29+
neon,
30+
"column",
31+
(c) => ({
32+
table: c.table,
33+
schema: c.schema,
34+
}),
35+
],
36+
label: "Lookup Column",
37+
description: "Find row to update by searching for a value in this column. Returns first row found",
38+
},
39+
value: {
40+
propDefinition: [
41+
neon,
42+
"value",
43+
(c) => ({
44+
table: c.table,
45+
column: c.column,
46+
schema: c.schema,
47+
}),
48+
],
49+
},
50+
rowValues: {
51+
propDefinition: [
52+
neon,
53+
"rowValues",
54+
],
55+
description: "JSON representation of your new table row values. For example: `{ \"product_name\": \"Laptop Pro 15\", \"price\": 1200.50, \"stock_quantity\": 50 }`",
56+
},
57+
},
58+
async run({ $ }) {
59+
const {
60+
schema,
61+
table,
62+
column,
63+
value,
64+
rowValues,
65+
} = this;
66+
67+
const parsedRowValues = parseRowValues(rowValues);
68+
const errorMsg = "Row not updated due to an error. ";
69+
70+
const res = await this.neon.updateRow(
71+
schema,
72+
table,
73+
column,
74+
value,
75+
parsedRowValues,
76+
errorMsg,
77+
);
78+
const summary = res
79+
? "Row updated"
80+
: "Row not found";
81+
$.export("$summary", summary);
82+
return res;
83+
},
84+
};

0 commit comments

Comments
 (0)