Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new Error('Invalid options argument. Options must contain: connection, nativeQuery, and leased.');
}
if (!_.has(options, 'connection') || !_.isObject(options.connection)) {
throw new Error('Invalid option used in options argument. Missing or invalid connection.');
}
if (!_.has(options, 'nativeQuery')) {
throw new Error('Invalid option used in options argument. Missing or invalid nativeQuery.');
}
// ╦═╗╦ ╦╔╗╔ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┌─┐ ┬ ┬┌─┐┬─┐┬ ┬
// ╠╦╝║ ║║║║ │││├─┤ │ │└┐┌┘├┤ │─┼┐│ │├┤ ├┬┘└┬┘
// ╩╚═╚═╝╝╚╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ └─┘└└─┘└─┘┴└─ ┴
PG.sendNativeQuery({
connection: options.connection,
nativeQuery: options.nativeQuery,
valuesToEscape: options.valuesToEscape,
})
.switch({
// If there was an error, check if the connection should be
// released back into the pool automatically.
error: function error(err) {
if (!options.disconnectOnError) {
return cb(err);
}
releaseConnection(options.connection, options.leased, function releaseConnectionCb(err) {
return cb(err);
});
},
module.exports = function runNativeQuery(connection, query, valuesToEscape, cb) {
PG.sendNativeQuery({
connection: connection,
nativeQuery: query,
valuesToEscape: valuesToEscape,
})
.switch({
error: function error(err) {
return cb(err);
},
// If the query failed, try and parse it into a normalized format.
queryFailed: function queryFailed(report) {
// Parse the native query error into a normalized format
var parsedError;
try {
parsedError = PG.parseNativeQueryError({
nativeQueryError: report.error
}).exec(function getConnectionCb(err, report) {
if (err) {
return cb(err);
}
var query = [
'INSERT INTO "' + tableName + '" ("fieldA", "fieldB", "fieldC", "fieldD") ',
'values (\'foo\', \'bar\', null, null), (\'foo_2\', \'bAr_2\', $1, $2);'
].join('');
PG.sendNativeQuery({
connection: report.connection,
nativeQuery: query,
valuesToEscape: [new Buffer([1, 2, 3]), new Date('2001-06-15 12:00:00')]
}).exec(function seedCb(err) {
if (err) {
return cb(err);
}
PG.releaseConnection({
connection: report.connection
}).exec(cb);
});
});
};