From 3c2829922df795c87b21fcac48cd441cb9eaf0c2 Mon Sep 17 00:00:00 2001 From: Iqueal Date: Sat, 23 Dec 2023 11:50:03 +0530 Subject: [PATCH] Improved string manipulation --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index d308068..c08c2d4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,9 +37,10 @@ async function readCSV(csvFileName = "", batchSize: number = 0) { }); const linesArray = data.split(/\r|\n/).filter((line) => line); const columnNames = linesArray?.shift()?.split(",") || []; - let beginSQLInsert = `INSERT INTO ${fileAndTableName} (`; - columnNames.forEach((name) => (beginSQLInsert += `${name}, `)); - beginSQLInsert = beginSQLInsert.slice(0, -2) + ")\nVALUES\n"; + + // Improved string manipulation using array join + const beginSQLInsert = `INSERT INTO ${fileAndTableName} (${columnNames.join(', ')})\nVALUES\n`; + let values = ""; linesArray.forEach((line, index) => { // Parses each line of CSV into field values array