seneca-import-csv

Import your CSV into seneca

SenecaImportCSV

Import a CSV into Seneca

$ npm install seneca-import-csv -g
$ seneca-import-csv.js -f your-csv.csv -e your-entity -c ./example-config.json
checking  [===================] 100% 0.0s
importing [==                 ] 14% 16.8s

You can also specify a -r file flag to say when and how to resume the import.

The importer supports both a JSON-based configuration and a module-based configuration.

{
  "store": "jsonfile-store",
  "opts": {
    "folder": "./db"
  }
}
module.exports = function(senecaJoi) {
  seneca.use('jsonfile-store', {
    "folder": "./db"
  })
 
  return Joi.object().keys({
    Yr: Joi.number().integer(),
    Mn: Joi.number().integer(),
    "Date Excel": Joi.number().integer(),
    Date: Joi.string(),
    "CO2 [ppm]": Joi.number()
  })
}

See the documentation of Joi for all the possible options with defining the schema. The options passed to the Joi.validate functions are convert: true and stripUnknown: true.

SenecaImportCSV allows to resume a previously stopped (or crashed) import sequence.

$ seneca-import-csv.js -f your-csv.csv -e your-entity -c ./example-config.json -r resume-file
checking  [===================] 100% 0.0s
importing [                   ] 6% 19.6s^C
$ seneca-import-csv.js -f your-csv.csv -e your-entity -c ./example-config.json -r resume-file
checking  [===================] 100% 0.0s
skipping 502 rows
importing [==                 ] 14% 8.7s^C
npm install seneca-import-csv --save
var seneca    = require('seneca')()
  , importer  = require('./')
 
seneca.use('jsonfile-store', {folder:'./db'})
 
seneca.ready(function() {
  var pear      = seneca.make('pear')
    , instance  = importer.entity(seneca, 'pear')
 
  instance.write('name,price\n')
  instance.write('hello,200\n')
  instance.end('matteo,400\n')
 
  instance.on('importCompleted', function() {
    pear.list$({}, function(errres) {
      console.log(res)
    })
  })
})
 
var seneca    = require('seneca')()
  , importer  = require('./')
  , pear      = seneca.make('pear')
  , pattern   = { sample: 'call' }
  , instance  = importer.act(s, pattern)
 
function check(arriveddone) {
  console.log(arrived)
  done()
}
 
s.add(pattern, check);
 
instance.write('name,price\n')
instance.write('hello,200\n')
instance.end('matteo,400\n')

This project was kindly sponsored by nearForm.

MIT