Skip to content

Commit 120113a

Browse files
committed
updates
1 parent f3c395a commit 120113a

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

components/neon_postgres/neon_postgres.app.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import postgresql from "@pipedream/postgresql";
2+
import format from "pg-format";
23

34
export default {
45
type: "app",
@@ -26,5 +27,30 @@ export default {
2627
ssl: this._getSslConfig(),
2728
};
2829
},
30+
upsertRow({
31+
schema, table, columns, values, conflictTarget = "id", errorMsg,
32+
} = {}) {
33+
const placeholders = this.getPlaceholders({
34+
values,
35+
});
36+
37+
const updates = columns
38+
.filter((column) => column !== conflictTarget)
39+
.map((column) => `${column}=EXCLUDED.${column}`);
40+
41+
const query = `
42+
INSERT INTO ${schema}.${table} (${columns})
43+
VALUES (${placeholders})
44+
ON CONFLICT (${conflictTarget})
45+
DO UPDATE SET ${updates}
46+
RETURNING *
47+
`;
48+
49+
return this.executeQuery({
50+
text: format(query, schema, table),
51+
values,
52+
errorMsg,
53+
});
54+
},
2955
},
3056
};

components/neon_postgres/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@pipedream/platform": "^3.0.3",
17-
"@pipedream/postgresql": "^2.2.3"
17+
"@pipedream/postgresql": "^2.2.3",
18+
"pg-format": "^1.0.4"
1819
}
1920
}

components/neon_postgres/sources/new-row-custom-query/new-row-custom-query.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default {
5656
}
5757

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

components/postgresql/sources/new-row-custom-query/new-row-custom-query.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default {
5656
}
5757

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

0 commit comments

Comments
 (0)