2018-02-03 08:33:02 -05:00
|
|
|
// Redshift
|
|
|
|
// -------
|
2020-10-05 23:59:12 +03:00
|
|
|
const { inherits } = require('util');
|
2019-06-04 00:37:17 +02:00
|
|
|
const Client_PG = require('../postgres');
|
2020-04-18 20:41:23 +03:00
|
|
|
const map = require('lodash/map');
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2019-06-04 00:37:17 +02:00
|
|
|
const Transaction = require('./transaction');
|
|
|
|
const QueryCompiler = require('./query/compiler');
|
|
|
|
const ColumnBuilder = require('./schema/columnbuilder');
|
|
|
|
const ColumnCompiler = require('./schema/columncompiler');
|
|
|
|
const TableCompiler = require('./schema/tablecompiler');
|
|
|
|
const SchemaCompiler = require('./schema/compiler');
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
function Client_Redshift(config) {
|
2018-07-09 08:10:34 -04:00
|
|
|
Client_PG.apply(this, arguments);
|
2018-02-03 08:33:02 -05:00
|
|
|
}
|
2018-07-09 08:10:34 -04:00
|
|
|
inherits(Client_Redshift, Client_PG);
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2019-07-10 22:38:20 +02:00
|
|
|
Object.assign(Client_Redshift.prototype, {
|
2018-02-03 08:33:02 -05:00
|
|
|
transaction() {
|
2018-07-09 08:10:34 -04:00
|
|
|
return new Transaction(this, ...arguments);
|
2018-02-03 08:33:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
queryCompiler() {
|
2018-07-09 08:10:34 -04:00
|
|
|
return new QueryCompiler(this, ...arguments);
|
2018-02-03 08:33:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
columnBuilder() {
|
|
|
|
return new ColumnBuilder(this, ...arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
columnCompiler() {
|
2018-07-09 08:10:34 -04:00
|
|
|
return new ColumnCompiler(this, ...arguments);
|
2018-02-03 08:33:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
tableCompiler() {
|
2018-07-09 08:10:34 -04:00
|
|
|
return new TableCompiler(this, ...arguments);
|
2018-02-03 08:33:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
schemaCompiler() {
|
2018-07-09 08:10:34 -04:00
|
|
|
return new SchemaCompiler(this, ...arguments);
|
2018-02-03 08:33:02 -05:00
|
|
|
},
|
2018-07-09 08:10:34 -04:00
|
|
|
|
2018-02-03 08:33:02 -05:00
|
|
|
dialect: 'redshift',
|
|
|
|
|
|
|
|
driverName: 'pg-redshift',
|
|
|
|
|
|
|
|
_driver() {
|
2018-07-09 08:10:34 -04:00
|
|
|
return require('pg');
|
2018-02-03 08:33:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
// Ensures the response is returned in the same format as other clients.
|
|
|
|
processResponse(obj, runner) {
|
|
|
|
const resp = obj.response;
|
|
|
|
if (obj.output) return obj.output.call(runner, resp);
|
|
|
|
if (obj.method === 'raw') return resp;
|
|
|
|
if (resp.command === 'SELECT') {
|
|
|
|
if (obj.method === 'first') return resp.rows[0];
|
|
|
|
if (obj.method === 'pluck') return map(resp.rows, obj.pluck);
|
|
|
|
return resp.rows;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
resp.command === 'INSERT' ||
|
|
|
|
resp.command === 'UPDATE' ||
|
|
|
|
resp.command === 'DELETE'
|
|
|
|
) {
|
|
|
|
return resp.rowCount;
|
|
|
|
}
|
|
|
|
return resp;
|
2018-07-09 08:10:34 -04:00
|
|
|
},
|
|
|
|
});
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2019-06-04 00:37:17 +02:00
|
|
|
module.exports = Client_Redshift;
|