Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Pool = require('pg').Pool;
  2. const csv = require('csv-parser');
  3. const fs = require('fs');
  4.  
  5. const pool = new Pool({
  6.   user: '***',
  7.   host: '***',
  8.   database: '***',
  9.   password: '***',
  10.   port: 5432
  11. });
  12.  
  13. fs.createReadStream('/home/***/fullAddress.csv')
  14.   .pipe(csv())
  15.   .on('data', (row) => {
  16.    
  17.     const url = "http://***/"+row.street_code+"/"+row.id+"/***";
  18.     const provider="***";
  19.     pool.query(
  20.         'INSERT INTO public.data (address_id, url, provider) VALUES ($1, $2, $3)',
  21.         [row.address_id, url, provider],
  22.         (error, results) => {
  23.           if (error) {
  24.             throw error
  25.           }
  26.         }
  27.       )
  28.   })
  29.   .on('end', () => {
  30.     console.log('CSV file successfully processed');
  31.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement