Skip to content

Commit 81abc12

Browse files
committed
move sql related components to neon_postgres
1 parent d174288 commit 81abc12

File tree

21 files changed

+858
-71
lines changed

21 files changed

+858
-71
lines changed

components/neon_api_keys/actions/create-branch/create-branch.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import app from "../../neon_api_keys.app.mjs";
22

33
export default {
44
name: "Create Branch",
5-
version: "0.0.2",
5+
version: "0.0.1",
66
key: "neon_api_keys-create-branch",
77
description: "Creates a branch in the project. [See the documentation](https://api-docs.neon.tech/reference/createprojectbranch)",
88
type: "action",

components/neon_api_keys/actions/create-database/create-database.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import app from "../../neon_api_keys.app.mjs";
22

33
export default {
44
name: "Create Database",
5-
version: "0.0.2",
5+
version: "0.0.1",
66
key: "neon_api_keys-create-database",
77
description: "Creates a database in the project. [See the documentation](https://api-docs.neon.tech/reference/createprojectbranchdatabase)",
88
type: "action",

components/neon_api_keys/actions/create-project/create-project.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import constants from "../common/constants.mjs";
33

44
export default {
55
name: "Create Project",
6-
version: "0.0.2",
6+
version: "0.0.1",
77
key: "neon_api_keys-create-project",
88
description: "Creates a project. [See the documentation](https://api-docs.neon.tech/reference/createproject)",
99
type: "action",

components/neon_api_keys/actions/find-row/find-row.mjs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ export default {
1212
propDefinition: [
1313
neon,
1414
"schema",
15-
(c) => ({
16-
connectionUriArgs: {
17-
projectId: c.projectId,
18-
params: {
19-
branchId: c.branchId,
20-
databaseName: c.databaseName,
21-
roleName: c.roleName,
22-
},
23-
},
24-
}),
2515
],
2616
},
2717
table: {
@@ -30,14 +20,6 @@ export default {
3020
"table",
3121
(c) => ({
3222
schema: c.schema,
33-
connectionUriArgs: {
34-
projectId: c.projectId,
35-
params: {
36-
branchId: c.branchId,
37-
databaseName: c.databaseName,
38-
roleName: c.roleName,
39-
},
40-
},
4123
}),
4224
],
4325
},
@@ -48,14 +30,6 @@ export default {
4830
(c) => ({
4931
table: c.table,
5032
schema: c.schema,
51-
connectionUriArgs: {
52-
projectId: c.projectId,
53-
params: {
54-
branchId: c.branchId,
55-
databaseName: c.databaseName,
56-
roleName: c.roleName,
57-
},
58-
},
5933
}),
6034
],
6135
label: "Lookup Column",

components/neon_api_keys/neon_api_keys.app.mjs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { axios } from "@pipedream/platform";
2-
import postgresql from "@pipedream/postgresql";
32

43
export default {
54
type: "app",
65
app: "neon_api_keys",
76
propDefinitions: {
8-
...postgresql.propDefinitions,
97
projectId: {
108
type: "string",
119
label: "Project ID",
@@ -51,36 +49,6 @@ export default {
5149
},
5250
},
5351
methods: {
54-
...postgresql.methods,
55-
_hasDbCredentials() {
56-
return this.$auth.host
57-
&& this.$auth.port
58-
&& this.$auth.user
59-
&& this.$auth.password
60-
&& this.$auth.database;
61-
},
62-
getClientConfiguration() {
63-
if (!this._hasDbCredentials()) {
64-
throw new Error("No database credentials found");
65-
}
66-
67-
const {
68-
host,
69-
port,
70-
user,
71-
password,
72-
database,
73-
} = this.$auth;
74-
75-
return {
76-
host,
77-
port,
78-
user,
79-
password,
80-
database,
81-
ssl: this._getSslConfig(),
82-
};
83-
},
8452
_apiKey() {
8553
return this.$auth.api_key;
8654
},

components/neon_api_keys/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/neon_api_keys",
3-
"version": "0.2.0",
3+
"version": "0.1.0",
44
"description": "Pipedream Neon (API Keys) Components",
55
"main": "neon_api_keys.app.mjs",
66
"keywords": [
@@ -13,7 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.3",
17-
"@pipedream/postgresql": "^2.2.3"
16+
"@pipedream/platform": "^1.5.1"
1817
}
1918
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
3+
export default {
4+
name: "Delete Row(s)",
5+
key: "neon_api_keys-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+
try {
59+
const rows = await this.neon.deleteRows(
60+
schema,
61+
table,
62+
column,
63+
value,
64+
);
65+
$.export("$summary", `Deleted ${rows.length} rows from ${table}`);
66+
return rows;
67+
} catch (error) {
68+
let errorMsg = "Row not deleted due to an error. ";
69+
errorMsg += `${error}`.includes("SSL verification failed")
70+
? "This could be because SSL verification failed. To resolve this, reconnect your account and set SSL Verification Mode: Skip Verification, and try again."
71+
: `${error}`;
72+
throw new Error(errorMsg);
73+
}
74+
},
75+
};
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_api_keys-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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
3+
export default {
4+
name: "Find Row With Custom Query",
5+
key: "neon_api_keys-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+
try {
46+
const res = await this.neon.executeQuery({
47+
text: query,
48+
values,
49+
});
50+
$.export("$summary", "Successfully executed query");
51+
return res;
52+
} catch (error) {
53+
let errorMsg = "Query not executed due to an error. ";
54+
errorMsg += `${error}`.includes("SSL verification failed")
55+
? "This could be because SSL verification failed. To resolve this, reconnect your account and set SSL Verification Mode: Skip Verification, and try again."
56+
: `${error}`;
57+
throw new Error(errorMsg);
58+
}
59+
},
60+
};
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import neon from "../../neon_postgres.app.mjs";
2+
3+
export default {
4+
name: "Find Row",
5+
key: "neon_api_keys-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+
try {
58+
const res = await this.neon.findRowByValue(
59+
schema,
60+
table,
61+
column,
62+
value,
63+
);
64+
const summary = res
65+
? "Row found"
66+
: "Row not found";
67+
$.export("$summary", summary);
68+
return res;
69+
} catch (error) {
70+
let errorMsg = "Row not retrieved due to an error. ";
71+
errorMsg += `${error}`.includes("SSL verification failed")
72+
? "This could be because SSL verification failed. To resolve this, reconnect your account and set SSL Verification Mode: Skip Verification, and try again."
73+
: `${error}`;
74+
throw new Error(errorMsg);
75+
}
76+
},
77+
};

0 commit comments

Comments
 (0)