singlemysqlcsv-cli
v0.0.1
Published
mysql single column update with csv file.
Downloads
3
Readme
singlemysqlcsv-cli
- mysql update by csv
- singlemydqlcsv can update single column at once.
- not support multi column update
Install
npm inatall singlemysqlcsv-cli
Support features:
- Update mysql single column
- Select key column
- Typescript support
Update Logic
- if mysql table name TableA have 3 Column CA, CB, CC and CA is main Key
- if A.csv have CSA key column and CSC column
- this module can be update column that one of TableA at once
- first of all select table
- second, select key column, this key column match to csv key column
- third, select table's column for update
- 4th, select csv file
- 5th, select csv key column, this key column match to db table key column
- 6th, select csv's column for update
How to run
- bin
- global npm install
singlemysqlcsv-cli
- code
- npm run start
- running
PS D:\dev\npms\csvupdater> npm run start > [email protected] start D:\dev\npms\csvupdater > nodemon --watch src --delay 1 --exec ts-node src/index.ts [nodemon] 2.0.6 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): src\**\* [nodemon] watching extensions: ts,json [nodemon] starting `ts-node src/index.ts` ____ ____ _ ____ ______ ___ __ _ ____ ____ _ _ _ _ _ ___ _ / ___|| __ ) ( )/ ___/ ___\ \ / ( ) \ \( ) _ \| __ )( ) | | | |_ __ __| | __ _| |_ ___ / _ \ / | \___ \| _ \ |/| | \___ \\ \ / /|/ _____\ \/| | | | _ \|/ | | | | '_ \ / _` |/ _` | __/ _ \ | | | || | ___) | |_) | | |___ ___) |\ V / |_____/ / | |_| | |_) | | |_| | |_) | (_| | (_| | || __/ | |_| || | |____/|____/ \____|____/ \_/ /_/ |____/|____/ \___/| .__/ \__,_|\__,_|\__\___| \___(_)_| |_| => Target DB host(default "localhost")? => Target DB user? quser => Target DB password? quser => Target DB database? sessions success connection => Source CSV file path? ./source.csv 7 row read ** Current CSV keys are ID,name,desc => Select Key Column: ID => Select Updated Data Column: name CSV "ID" ---> mapping Table and Column Select: => Select Mapping DB Table: test => Select Mapping DB Key Column: id => Select Mapping DB Update Column: name => "ID" mapping --> "test/id" sure?(y/n)y => "name" update --> "test/name" sure?(y/n)y ************************************************************************** Key Mapping CSV[ID]--> DB[test/id] Update Mapping CSV[name]--> DB[test/name]
let see, above example
this example show how to update sessions DB by using source.csv file.
as you can see, sessions DB's test table have id column, this id column is matched source.csv id column. and name column update by soure.csv name column.
if(sessions.test.id == source.csv.id) { sessions.test.name = source.csv.name }
above pseudocode can expain total logic.
Build
- npm run build
- out put folder is 'dist'