From 60315c5170bab842a2d8ed57ffe2617521b1e1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20Kay=C4=B1=C5=9F?= Date: Sat, 23 Dec 2023 20:59:45 +0300 Subject: [PATCH 1/2] improve beginSQLInsert --- src/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index d308068..93aa45e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,9 +37,7 @@ 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"; + const beginSQLInsert = `INSERT INTO ${fileAndTableName} (${columnNames.join(", ")})\nVALUES\n`; let values = ""; linesArray.forEach((line, index) => { // Parses each line of CSV into field values array From 89d48e726faf5880f073bab1543fcd032460717f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20Kay=C4=B1=C5=9F?= Date: Sat, 23 Dec 2023 22:19:24 +0300 Subject: [PATCH 2/2] fix creating sql folder --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 93aa45e..039fd78 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ async function writeSQL(statement: string, saveFileAs = "", isAppend: boolean = if (!destinationFile) { throw new Error("Missing saveFileAs parameter"); } - createIfNot(path.resolve(`./sql/${destinationFile}.sql`)) + createIfNot(path.resolve('./sql')) if(isAppend){ await fs.appendFile(`sql/${process.argv[2]}.sql`, statement); }else{