@@ -3,15 +3,14 @@ import {createIfNot} from "./utils/fileUtils.js"
3
3
import * as path from "node:path"
4
4
async function writeSQL ( statement : string , saveFileAs = "" , isAppend : boolean = false ) {
5
5
try {
6
- const destinationFile = process . argv [ 2 ] || saveFileAs ;
7
- if ( ! destinationFile ) {
6
+ if ( ! saveFileAs ) {
8
7
throw new Error ( "Missing saveFileAs parameter" ) ;
9
8
}
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 ) ;
13
12
} else {
14
- await fs . writeFile ( `sql/${ process . argv [ 2 ] } .sql` , statement ) ;
13
+ await fs . writeFile ( `sql/${ saveFileAs } .sql` , statement ) ;
15
14
}
16
15
} catch ( err ) {
17
16
console . log ( err ) ;
@@ -20,10 +19,10 @@ async function writeSQL(statement: string, saveFileAs = "", isAppend: boolean =
20
19
21
20
async function readCSV ( csvFileName = "" , batchSize : number = 0 ) {
22
21
try {
23
- const fileAndTableName = process . argv [ 2 ] || csvFileName ;
22
+ const fileAndTableName = csvFileName || 'output' ;
24
23
25
- batchSize = parseInt ( process . argv [ 3 ] ) || batchSize || 500 ;
26
- let isAppend : boolean = false ;
24
+ batchSize = batchSize || 500 ;
25
+ let isAppend : boolean = false ;
27
26
28
27
if ( ! fileAndTableName ) {
29
28
throw new Error ( "Missing csvFileName parameter" ) ;
@@ -91,5 +90,8 @@ async function readCSV(csvFileName = "", batchSize: number = 0) {
91
90
console . log ( err ) ;
92
91
}
93
92
}
94
- readCSV ( ) ;
93
+
94
+ const outputFileName = process . argv [ 2 ] ;
95
+ const batchSize = parseInt ( process . argv [ 3 ] ) ;
96
+ readCSV ( outputFileName , batchSize ) ;
95
97
console . log ( "Finished!" ) ;
0 commit comments