2018-02-03 08:33:02 -05:00
|
|
|
// Redshift Query Builder & Compiler
|
|
|
|
|
// ------
|
2021-01-09 17:59:53 +02:00
|
|
|
const QueryCompiler = require('../../../query/querycompiler');
|
2021-01-07 17:31:56 +02:00
|
|
|
const QueryCompiler_PG = require('../../postgres/query/pg-querycompiler');
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2020-04-18 20:41:23 +03:00
|
|
|
const identity = require('lodash/identity');
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2020-02-01 21:52:00 +05:30
|
|
|
class QueryCompiler_Redshift extends QueryCompiler_PG {
|
2018-02-03 08:33:02 -05:00
|
|
|
truncate() {
|
|
|
|
|
return `truncate ${this.tableName.toLowerCase()}`;
|
2020-02-01 21:52:00 +05:30
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
|
// Compiles an `insert` query, allowing for multiple
|
|
|
|
|
// inserts using a single query statement.
|
|
|
|
|
insert() {
|
|
|
|
|
const sql = QueryCompiler.prototype.insert.apply(this, arguments);
|
|
|
|
|
if (sql === '') return sql;
|
|
|
|
|
this._slightReturn();
|
|
|
|
|
return {
|
|
|
|
|
sql,
|
|
|
|
|
};
|
2020-02-01 21:52:00 +05:30
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
|
// Compiles an `update` query, warning on unsupported returning
|
|
|
|
|
update() {
|
|
|
|
|
const sql = QueryCompiler.prototype.update.apply(this, arguments);
|
|
|
|
|
this._slightReturn();
|
|
|
|
|
return {
|
|
|
|
|
sql,
|
|
|
|
|
};
|
2020-02-01 21:52:00 +05:30
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
|
// Compiles an `delete` query, warning on unsupported returning
|
|
|
|
|
del() {
|
|
|
|
|
const sql = QueryCompiler.prototype.del.apply(this, arguments);
|
|
|
|
|
this._slightReturn();
|
|
|
|
|
return {
|
|
|
|
|
sql,
|
|
|
|
|
};
|
2020-02-01 21:52:00 +05:30
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
|
// simple: if trying to return, warn
|
2018-07-09 08:10:34 -04:00
|
|
|
_slightReturn() {
|
2018-02-03 08:33:02 -05:00
|
|
|
if (this.single.isReturning) {
|
2018-05-29 17:42:03 +02:00
|
|
|
this.client.logger.warn(
|
|
|
|
|
'insert/update/delete returning is not supported by redshift dialect'
|
|
|
|
|
);
|
2018-02-03 08:33:02 -05:00
|
|
|
}
|
2020-02-01 21:52:00 +05:30
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
|
forUpdate() {
|
2018-05-29 17:42:03 +02:00
|
|
|
this.client.logger.warn('table lock is not supported by redshift dialect');
|
2018-02-03 08:33:02 -05:00
|
|
|
return '';
|
2020-02-01 21:52:00 +05:30
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
|
forShare() {
|
2018-07-09 08:10:34 -04:00
|
|
|
this.client.logger.warn(
|
|
|
|
|
'lock for share is not supported by redshift dialect'
|
|
|
|
|
);
|
2018-02-03 08:33:02 -05:00
|
|
|
return '';
|
2020-02-01 21:52:00 +05:30
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2021-10-23 14:01:36 +01:00
|
|
|
forNoKeyUpdate() {
|
|
|
|
|
this.client.logger.warn('table lock is not supported by redshift dialect');
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forKeyShare() {
|
|
|
|
|
this.client.logger.warn(
|
|
|
|
|
'lock for share is not supported by redshift dialect'
|
|
|
|
|
);
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 08:33:02 -05:00
|
|
|
// Compiles a columnInfo query
|
|
|
|
|
columnInfo() {
|
|
|
|
|
const column = this.single.columnInfo;
|
2018-04-04 18:43:39 -04:00
|
|
|
let schema = this.single.schema;
|
|
|
|
|
|
|
|
|
|
// The user may have specified a custom wrapIdentifier function in the config. We
|
|
|
|
|
// need to run the identifiers through that function, but not format them as
|
|
|
|
|
// identifiers otherwise.
|
|
|
|
|
const table = this.client.customWrapIdentifier(this.single.table, identity);
|
|
|
|
|
|
|
|
|
|
if (schema) {
|
|
|
|
|
schema = this.client.customWrapIdentifier(schema, identity);
|
|
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2021-11-09 09:34:19 +01:00
|
|
|
const sql =
|
2018-07-09 08:10:34 -04:00
|
|
|
'select * from information_schema.columns where table_name = ? and table_catalog = ?';
|
|
|
|
|
const bindings = [
|
|
|
|
|
table.toLowerCase(),
|
|
|
|
|
this.client.database().toLowerCase(),
|
|
|
|
|
];
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2021-11-09 09:34:19 +01:00
|
|
|
return this._buildColumnInfoQuery(schema, sql, bindings, column);
|
2020-02-01 21:52:00 +05:30
|
|
|
}
|
|
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2019-06-04 00:37:17 +02:00
|
|
|
module.exports = QueryCompiler_Redshift;
|