-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f813f3c
new components
michelle0927 b5404dd
add error
michelle0927 9abb005
pnpm-lock.yaml
michelle0927 d174288
Merge remote-tracking branch 'origin/master' into issue-16620
michelle0927 81abc12
move sql related components to neon_postgres
michelle0927 110e30c
pnpm-lock.yaml
michelle0927 b51cb96
pnpm-lock.yaml
michelle0927 d792a55
remove sql related components from neon_api_keys
michelle0927 ea358df
fix keys
michelle0927 af92d5a
updates
michelle0927 f3c395a
postgresql package version
michelle0927 120113a
updates
michelle0927 e72e36f
pnpm-lock.yaml
michelle0927 eb49c5a
Merge remote-tracking branch 'origin/master' into issue-16620
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
components/neon_postgres/actions/delete-rows/delete-rows.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
28 changes: 28 additions & 0 deletions
28
components/neon_postgres/actions/execute-custom-query/execute-custom-query.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
53 changes: 53 additions & 0 deletions
53
components/neon_postgres/actions/find-row-custom-query/find-row-custom-query.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
68
components/neon_postgres/actions/insert-row/insert-row.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
84
components/neon_postgres/actions/update-row/update-row.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.