node-postgres/test/integration/gh-issues/699-tests.js

31 lines
744 B
JavaScript
Raw Normal View History

2014-12-12 16:23:09 +08:00
var helper = require('../test-helper');
var assert = require('assert');
var copyFrom = require('pg-copy-streams').from;
helper.pg.connect(function (err, client, done) {
if (err) throw err;
var c = 'CREATE TEMP TABLE employee (id integer, fname varchar(400), lname varchar(400))';
client.query(c, function (err) {
if (err) throw err;
var stream = con.query(copyFrom("COPY employee FROM STDIN"));
stream.on('end', function () {
done();
helper.pg.end();
});
stream.on('error', function () {
throw new Error('Error in copy stream');
});
for (var i = 1; i <= 5; i++) {
var line = ['1\ttest', i, '\tuser', i, '\n'];
stream.write(line.join(''));
}
stream.end();
});
});