JSPM

csv2sql-stream

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q33400F
  • License ISC

csv2sql =======

Package Exports

  • csv2sql-stream

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (csv2sql-stream) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

csv2sql - Stream Transformer

csv2sql is a Stream Transformer that lets you transform a Stream of CSV data to an SQL Writable Stream

Installation

npm install csv2sql

Methods

transform(tablename, readstream)

Using pipe

var csv2sql = require('csv2sql');
csv2sql.transform("DOGS", fs.createReadStream('./test.csv')).pipe(process.stdout);

outputs:

INSERT INTO DOGS (id, name, breed) VALUES ('1', 'Bailey', 'Akita');
INSERT INTO DOGS (id, name, breed) VALUES ('2', 'Max', 'Dalmatian');
INSERT INTO DOGS (id, name, breed) VALUES ('3', 'Charlie', 'Great Dane');
INSERT INTO DOGS (id, name, breed) VALUES ('4', 'Lucy', 'Maltese');

Using pipe

var csv2sql = require('csv2sql');
csv2sql.transform("DOGS", fs.createReadStream('./dogs.csv')).pipe(process.stdout);

Using events

var csv2sql = require('csv2sql');
csv2sql.transform("DOGS",fs.createReadStream('./dogs.csv'))
.on('data',function(sql){
    console.log(sql); //INSERT INTO DOGS ...
})
.on('end',function(rows){
    console.log(rows); // 5 - Num of rows handled, including header
})
.on('error', function(error){
    console.error(error); //Handle error
})