Comparing version 0.13.0 to 0.14.0
@@ -15,8 +15,4 @@ "use strict"; | ||
makePool = require('./pool'), | ||
makeStore = require('./store').store, | ||
copyFrom = require('pg-copy-streams').from, | ||
Readable = require('stream').Readable, | ||
csvStringify = require('csv-stringify'); | ||
makeStore = require('./store').store; | ||
function compileTemplate(content) { | ||
@@ -183,2 +179,7 @@ return handlebars.compile(content, {noEscape: true}); | ||
Connection.prototype.driver = function() { | ||
var self = this; | ||
return self.pgConnection.driver(); | ||
} | ||
Connection.prototype.query = function() { | ||
@@ -191,32 +192,2 @@ return this.queryRaw.apply(this, arguments) | ||
Connection.prototype.writeRows = function(tableName, rows) { | ||
var self = this; | ||
return new Promise(function(resolve, reject) { | ||
if (!rows.length) { | ||
resolve(); | ||
return; | ||
} | ||
var columns = '(' + _.map(_.keys(rows[0]), _.snakeCase).join(', ') + ')'; | ||
var dbOutStream = self.pgConnection.driverQuery( | ||
copyFrom('COPY ' + tableName + ' ' + columns + ' FROM STDIN CSV') | ||
); | ||
var csvInStream = Readable(); | ||
csvStringify(rows, {}, function(err, csvData) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
csvInStream.on('error', reject); | ||
dbOutStream.on('error', reject); | ||
dbOutStream.on('end', resolve); | ||
csvInStream._read = function noop() {}; | ||
csvInStream.push(csvData); | ||
csvInStream.push(null); | ||
csvInStream.pipe(dbOutStream); | ||
}); | ||
}); | ||
} | ||
Connection.prototype.queryRaw = function(text, vals) { | ||
@@ -450,8 +421,2 @@ var self = this; | ||
client.writeRows = function(rows) { | ||
return useConnection( function(conn) { | ||
return conn.writeRows(rows); | ||
}); | ||
} | ||
// Returns a promise for work completed against a connection. | ||
@@ -458,0 +423,0 @@ // |
{ | ||
"name": "dbeasy", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "Promise-based wrapper for postgresql with helpers for transactions.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -37,7 +37,6 @@ 'use strict'; | ||
return pgPool.connectAsync() | ||
.spread(function(connection, release) { | ||
connection = { | ||
query: Promise.promisify(connection.query, connection), | ||
driverQuery: _.bind(connection.query, connection) | ||
.spread(function(pgConn, release) { | ||
var connection = { | ||
query: Promise.promisify(pgConn.query, pgConn), | ||
driver: function() { return pgConn; } | ||
}; | ||
@@ -44,0 +43,0 @@ return Promise.try(fn, connection) |
70731
42
1983