Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const csv = require('csv-parser')
- const fs = require('fs')
- function esc (str) {
- return str.replace(/'/g, "''")
- }
- function main () {
- const rows = []
- fs.createReadStream('file.csv')
- .pipe(csv({separator: ';'}))
- .on('data', (row) => {
- rows.push({
- name: row['Col 1 Name'],
- code: row['Col 2 Name']
- })
- })
- .on('end', () => {
- console.log('INSERT INTO table (code, name) VALUES ')
- for (const row of rows) {
- console.log(`('${esc(row.code)}','${esc(row.name)}),`)
- }
- })
- }
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement