Created
January 29, 2015 00:01
-
-
Save MrLeebo/447344bb8068b69c60cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert = require 'assert' | |
fs = require 'fs' | |
{ from } = require 'pg-copy-streams' | |
knex = require './knex' # knex instance with dbConfig | |
module.exports = (done) -> | |
runner = new knex.client.Runner(knex.client) | |
runner.ensureConnection().then (conn) -> | |
sql = "copy import_data from stdin with csv header null '' delimiter '|' encoding 'windows-1251';" | |
sqlStream = conn.query(from(sql)).on 'end', -> | |
knex.raw('select count(*) from import_data').then (results) -> | |
runner.cleanupConnection() | |
done(results.rows[0].count) | |
fs.createReadStream('import_data.txt').pipe(sqlStream) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert = require 'assert' | |
fs = require 'fs' | |
{ from } = require 'pg-copy-streams' | |
knex = require './knex' # knex instance with dbConfig | |
module.exports = (done) -> | |
runner = new knex.client.Runner(knex.client) | |
runner.ensureConnection().then (conn) -> | |
sql = "copy import_data from stdin with csv header null '' delimiter '|' encoding 'windows-1251';" | |
sqlStream = conn.query(from(sql)) | |
fs.createReadStream('import_data.txt').pipe(sqlStream).on 'finish', -> | |
knex.raw('select count(*) from import_data').then (results) -> | |
runner.cleanupConnection() | |
done(results.rows[0].count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment