To modify the code to include all available columns in table2, you can use a custom query with a JOIN statement. Here’s the updated Node.js code using Pipedream component code: ```
import pg from “pg”; export default defineComponent({ props: { postgresql: { type: “app”, app: “postgresql”, }, schema: { type: “string”, label: “Schema”, description: “Select the schema you want to use”, // Add options method if needed }, table1: { type: “string”, label: “Table 1”, description: “Select the first table you want to compare”, // Add options method if needed }, table2: { type: “string”, label: “Table 2”, description: “Select the second table you want to compare”, // Add options method if needed }, column: { type: “string”, label: “Column”, description: “Enter the column name you want to compare”, }, }, async run({ steps, $ }) { const { host, user, password, port, database } = this.postgresql.$auth; const client = new pg.Client({ host, database, user, password, port, }); await client.connect(); const query = SELECT t2.* FROM "${this.schema}"."${this.table1}" t1 JOIN "${this.schema}"."${this.table2}" t2 ON t1."${this.column}" = t2."${this.column}" ; const result = await client.query(query); await client.end(); return result.rows; }, });
To modify the code to check if the “TF” column in table 2 contains the text “240m” before displaying the result, you can add a WHERE clause to the query. Here’s the updated code: ```
import pg from “pg”; export default defineComponent({ props: { postgresql: { type: “app”, app: “postgresql”, }, schema: { type: “string”, label: “Schema”, description: “Select the schema you want to use”, }, table1: { type: “string”, label: “Table 1”, description: “Select the first table you want to compare”, }, table2: { type: “string”, label: “Table 2”, description: “Select the second table you want to compare”, }, column: { type: “string”, label: “Column”, description: “Enter the column name you want to compare”, }, }, async run({ steps, $ }) { const { host, user, password, port, database } = this.postgresql.$auth; const client = new pg.Client({ host, database, user, password, port, }); await client.connect(); const query = SELECT t2.* FROM "${this.schema}"."${this.table1}" t1 JOIN "${this.schema}"."${this.table2}" t2 ON t1."${this.column}" = t2."${this.column}" WHERE t2."TF" = '240m' ; const result = await client.query(query); await client.end(); return result.rows; }, });
To modify the code to check if the “TF” column in table 2 contains the text “240m” before comparing the tables, you can add a WHERE clause to the query. Here’s the updated code: ```
import pg from “pg”; export default defineComponent({ props: { postgresql: { type: “app”, app: “postgresql”, }, schema: { type: “string”, label: “Schema”, description: “Select the schema you want to use”, }, table1: { type: “string”, label: “Table 1”, description: “Select the first table you want to compare”, }, table2: { type: “string”, label: “Table 2”, description: “Select the second table you want to compare”, }, column: { type: “string”, label: “Column”, description: “Enter the column name you want to compare”, }, }, async run({ steps, $ }) { const { host, user, password, port, database } = this.postgresql.$auth; const client = new pg.Client({ host, database, user, password, port, }); await client.connect(); const query = SELECT t2.* FROM "${this.schema}"."${this.table1}" t1 JOIN "${this.schema}"."${this.table2}" t2 ON t1."${this.column}" = t2."${this.column}" WHERE t2."TF" = '240m' ; const result = await client.query(query); await client.end(); return result.rows; }, });
To modify the code to check if the “Symbols” column contains the text “USDCAD” after checking the “TF” column, you can add an additional condition to the WHERE clause. Here’s the updated code: ```
import pg from “pg”; export default defineComponent({ props: { postgresql: { type: “app”, app: “postgresql”, }, schema: { type: “string”, label: “Schema”, description: “Select the schema you want to use”, }, table1: { type: “string”, label: “Table 1”, description: “Select the first table you want to compare”, }, table2: { type: “string”, label: “Table 2”, description: “Select the second table you want to compare”, }, column: { type: “string”, label: “Column”, description: “Enter the column name you want to compare”, }, }, async run({ steps, $ }) { const { host, user, password, port, database } = this.postgresql.$auth; const client = new pg.Client({ host, database, user, password, port, }); await client.connect(); const query = SELECT t2.* FROM "${this.schema}"."${this.table1}" t1 JOIN "${this.schema}"."${this.table2}" t2 ON t1."${this.column}" = t2."${this.column}" WHERE t2."TF" = '240m' AND t2."Symbols" = 'USDCAD' ; const result = await client.query(query); await client.end(); return result.rows; }, });
To add options for the user to input the “TF” and “Symbols” values in the settings, you can modify the component’s props to include these inputs. Here’s the updated code: import pg from "pg"; export default defineComponent({ props: { postgresql: { type: "app", app: "postgresql", }, schema: { type: "string", label: "Schema", description: "Select the schema you want to use", }, table1: { type: "string", label: "Table 1", description: "Select the first table you want to compare", }, table2: { type: "string", label: "Table 2", description: "Select the second table you want to compare", }, column: { type: "string", label: "Column", description: "Enter the column name you want to compare", }, tfValue: { type: "string", label: "TF Value", description: "Enter the value for the TF column", }, symbolsValue: { type: "string", label: "Symbols Value", description: "Enter the value for the Symbols column", }, }, async run({ steps, $ }) { const { host, user, password, port, database } = this.postgresql.$auth; const client = new pg.Client({ host, database, user, password, port, }); await client.connect(); const query = ` SELECT t2.* FROM "${this.schema}"."${this.table1}" t1 JOIN "${this.schema}"."${this.table2}" t2 ON t1."${this.column}" = t2."${this.column}" WHERE t2."TF" = '${this.tfValue}' AND t2."Symbols" = '${this.symbolsValue}' `; const result = await client.query(query); await client.end(); return result.rows; }, }); Now, the user can input the “TF” and “Symbols” values using the tfValue and symbolsValue props in the settings.
In rowValues, add the following lines as defaults:
DATE: {{steps.data_processing_discord.Data}}
TIME: {{steps.data_processing_discord.Time}}
TIME CLOSE CANDLE:{{steps.data_processing_discord[“Time Close Candle”]}}
To add the default values for “DATE”, “TIME”, and “TIME CLOSE CANDLE” in the rowValues prop, you can use the default property. Here’s the updated code: import pg from "pg"; export default defineComponent({ props: { postgresql: { type: "app", app: "postgresql", }, schema: { type: "string", label: "Schema", description: "Select the schema you want to use", }, table: { type: "string", label: "Table", description: "Select the table you want to insert the row into", }, rowValues: { type: "object", label: "Row Values", description: "Enter the row values as an object", default: { DATE: "{{steps.data_processing_discord.Data}}", TIME: "{{steps.data_processing_discord.Time}}", "TIME CLOSE CANDLE": "{{steps.data_processing_discord['Time Close Candle']}}", }, }, }, async run({ steps, $ }) { const { host, user, password, port, database } = this.postgresql.$auth; const client = new pg.Client({ host, database, user, password, port, }); await client.connect(); const keys = Object.keys(this.rowValues).map((key) => `"${key}"`).join(", "); const values = Object.values(this.rowValues) .map((value) => (typeof value === "string" ? `'${value}'` : value)) .join(", "); const query = `INSERT INTO "${this.schema}"."${this.table}" (${keys}) VALUES (${values})`; await client.query(query); await client.end(); }, }); Now, the “DATE”, “TIME”, and “TIME CLOSE CANDLE” values in the rowValues prop will have default values based on the steps.data_processing_discord.Data, steps.data_processing_discord.Time, and steps.data_processing_discord['Time Close Candle'] variables.
To create a Node.js code based on the ‘add_single_row’ action of the Google Sheets app, you can use the following Pipedream component: import { GoogleSheets } from "@pipedream/platform"; export default defineComponent({ props: { googleSheets: { type: "app", app: "google_sheets", }, spreadsheetId: { type: "string", label: "Spreadsheet ID", description: "The ID of the Google Sheet you want to add the row to", }, sheetName: { type: "string", label: "Sheet Name", description: "The name of the sheet where you want to add the row", }, rowValues: { type: "string[]", label: "Row Values", description: "Enter the values for each cell in the row", }, }, async run({ steps, $ }) { const sheets = new GoogleSheets(this.googleSheets.$auth); const range = `${this.sheetName}!A:${String.fromCharCode(64 + this.rowValues.length)}`; const response = await sheets.addSingleRow(this.spreadsheetId, range, this.rowValues); return response; }, }); This component will add a single row to the specified Google Sheet using the ‘add_single_row’ action. You’ll need to provide the spreadsheetId, sheetName, and rowValues as props.