Skip to content

Instantly share code, notes, and snippets.

@kuanb
Created October 26, 2016 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuanb/ac93f058581c4511ef99efce8a52a551 to your computer and use it in GitHub Desktop.
Save kuanb/ac93f058581c4511ef99efce8a52a551 to your computer and use it in GitHub Desktop.
'use strict';
const fs = require('fs');
const parse = require('csv-parse');
const db = require('knex')({
client: 'postgresql',
connection: {
user: '',
database: 'clientcomm',
},
});
var csvData=[];
fs.createReadStream('./devTools/output.csv')
.pipe(parse({delimiter: ','}))
.on('data', function(csvrow) {
let insert = {
oi_clid: csvrow[0] || null,
os_lname: csvrow[1] || null,
os_fname: csvrow[2] || null,
os_mname: csvrow[3] || null,
os_sfx_name: csvrow[4] || null,
od_dob: csvrow[5] || null,
oi_ofndr_num: csvrow[6] || null,
oi_so_num: csvrow[7] || null,
os_prev_supr: csvrow[8] == 'Y' ? true : false,
oi_prev_agcy_id: csvrow[9] || null,
oi_slpri_score: csvrow[10] || null,
oi_slpri_fta: csvrow[11] || null,
oi_slpri_rcd: csvrow[12] || null,
os_degree_list: csvrow[13] || null,
os_ncic_list: csvrow[14] || null,
os_ofnse_typ_list: csvrow[15] || null,
oi_crnt_agcy_id: csvrow[16] || null,
od_strt_dt: csvrow[17] || null,
od_end_dt: csvrow[18] || null,
oi_discharge_cd: csvrow[19] || null,
os_discharge_desc: csvrow[20] || null,
os_addr: csvrow[21] || null,
os_city: csvrow[22] || null,
os_st: csvrow[23] || null,
os_zip: csvrow[24] || null,
och_sex: csvrow[25] || null,
os_race: csvrow[26] || null,
os_marital: csvrow[27] || null,
os_age: csvrow[28] || null,
od_crt_dt: csvrow[29] || null,
os_crt_tm: csvrow[30] || null,
os_crt_rm: csvrow[31] || null,
os_crt_loc: csvrow[32] || null,
os_judge: csvrow[33] || null,
os_slpri_desc: csvrow[34] || null,
};
csvData.push(insert);
}).on('end', function() {
csvData.shift(0);
let insert = csvData;
db('ctracks')
.insert(insert)
// .limit(1)
.then(function (ok) {
console.log('ok', ok);
}).catch(function (error) {
console.log(error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment