@@ -3,15 +3,14 @@ import {createIfNot} from "./utils/fileUtils.js"
33import * as path from "node:path"
44async function writeSQL ( statement : string , saveFileAs = "" , isAppend : boolean = false ) {
55 try {
6- const destinationFile = process . argv [ 2 ] || saveFileAs ;
7- if ( ! destinationFile ) {
6+ if ( ! saveFileAs ) {
87 throw new Error ( "Missing saveFileAs parameter" ) ;
98 }
10- createIfNot ( path . resolve ( `./sql/${ destinationFile } .sql` ) )
11- if ( isAppend ) {
12- await fs . appendFile ( `sql/${ process . argv [ 2 ] } .sql` , statement ) ;
9+ createIfNot ( path . resolve ( `./sql/${ saveFileAs } .sql` ) )
10+ if ( isAppend ) {
11+ await fs . appendFile ( `sql/${ saveFileAs } .sql` , statement ) ;
1312 } else {
14- await fs . writeFile ( `sql/${ process . argv [ 2 ] } .sql` , statement ) ;
13+ await fs . writeFile ( `sql/${ saveFileAs } .sql` , statement ) ;
1514 }
1615 } catch ( err ) {
1716 console . log ( err ) ;
@@ -20,10 +19,10 @@ async function writeSQL(statement: string, saveFileAs = "", isAppend: boolean =
2019
2120async function readCSV ( csvFileName = "" , batchSize : number = 0 ) {
2221 try {
23- const fileAndTableName = process . argv [ 2 ] || csvFileName ;
22+ const fileAndTableName = csvFileName || 'output' ;
2423
25- batchSize = parseInt ( process . argv [ 3 ] ) || batchSize || 500 ;
26- let isAppend : boolean = false ;
24+ batchSize = batchSize || 500 ;
25+ let isAppend : boolean = false ;
2726
2827 if ( ! fileAndTableName ) {
2928 throw new Error ( "Missing csvFileName parameter" ) ;
@@ -91,5 +90,8 @@ async function readCSV(csvFileName = "", batchSize: number = 0) {
9190 console . log ( err ) ;
9291 }
9392}
94- readCSV ( ) ;
93+
94+ const outputFileName = process . argv [ 2 ] ;
95+ const batchSize = parseInt ( process . argv [ 3 ] ) ;
96+ readCSV ( outputFileName , batchSize ) ;
9597console . log ( "Finished!" ) ;
0 commit comments