But I am receiving this error: "error": "As a result of LOCAL INFILE command server wants to read arquivo.csv file, but as of v2.0 you must provide streamFactory option returning ReadStream."
I couldn´t find a solution. Can someone help me? Thanks!
Solution
Hi @Hamilton T da Silva,
I'd start by breaking this up into at least 2 nodes: one to handle import from csv and a second for loading to the DB. My preference would be to import from the csv to JSON and then load the JSON via the SQL Insert row node (in the attached screenshot).
You could use something like this to convert a line from the csv to JSON:
import { Storage } from '@google-cloud/storage'; import parse from 'csv-parse/lib/sync'; // Import the sync parse method
// Assuming we're reading just one line and it includes headers const records = parse(contentString, { columns: true, // Automatically infer column names from the first row skip_empty_lines: true, // Skip empty lines from_line: 2, // Skip the header row, start with data max_record_size: 1 // Read only one record });
// Convert the first record (if it exists) to JSON const json = records[0] ? records[0] : null;
return json; // This will be your JSON object from the first line of data (excluding header) }
Of course this is only a starting point and YMMV - I have not tested this flow, but happy to work with you if you need further help.