2018-02-03 08:33:02 -05:00
|
|
|
// Redshift Column Compiler
|
|
|
|
// -------
|
|
|
|
|
2021-01-01 17:46:10 +02:00
|
|
|
const ColumnCompiler_PG = require('../../postgres/schema/pg-columncompiler');
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2021-01-01 20:35:54 +02:00
|
|
|
class ColumnCompiler_Redshift extends ColumnCompiler_PG {
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
// Types:
|
|
|
|
// ------
|
2021-01-01 20:35:54 +02:00
|
|
|
|
2018-02-03 08:33:02 -05:00
|
|
|
bit(column) {
|
|
|
|
return column.length !== false ? `char(${column.length})` : 'char(1)';
|
2021-01-01 20:35:54 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 08:33:02 -05:00
|
|
|
datetime(without) {
|
|
|
|
return without ? 'timestamp' : 'timestamptz';
|
2021-01-01 20:35:54 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 08:33:02 -05:00
|
|
|
timestamp(without) {
|
|
|
|
return without ? 'timestamp' : 'timestamptz';
|
2021-01-01 20:35:54 +02:00
|
|
|
}
|
2018-02-03 08:33:02 -05:00
|
|
|
|
|
|
|
// Modifiers:
|
|
|
|
// ------
|
|
|
|
comment(comment) {
|
2020-04-19 00:40:23 +02:00
|
|
|
this.pushAdditional(function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
this.pushQuery(
|
|
|
|
`comment on column ${this.tableCompiler.tableName()}.` +
|
|
|
|
this.formatter.wrap(this.args[0]) +
|
|
|
|
' is ' +
|
|
|
|
(comment ? `'${comment}'` : 'NULL')
|
|
|
|
);
|
2018-02-03 08:33:02 -05:00
|
|
|
}, comment);
|
2021-01-01 20:35:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-03 13:47:32 +01:00
|
|
|
ColumnCompiler_Redshift.prototype.increments = ({ primaryKey = true } = {}) =>
|
|
|
|
'integer identity(1,1)' + (primaryKey ? ' primary key' : '') + ' not null';
|
|
|
|
ColumnCompiler_Redshift.prototype.bigincrements = ({
|
|
|
|
primaryKey = true,
|
|
|
|
} = {}) =>
|
|
|
|
'bigint identity(1,1)' + (primaryKey ? ' primary key' : '') + ' not null';
|
2021-01-01 20:35:54 +02:00
|
|
|
ColumnCompiler_Redshift.prototype.binary = 'varchar(max)';
|
|
|
|
ColumnCompiler_Redshift.prototype.blob = 'varchar(max)';
|
|
|
|
ColumnCompiler_Redshift.prototype.enu = 'varchar(255)';
|
|
|
|
ColumnCompiler_Redshift.prototype.enum = 'varchar(255)';
|
|
|
|
ColumnCompiler_Redshift.prototype.json = 'varchar(max)';
|
|
|
|
ColumnCompiler_Redshift.prototype.jsonb = 'varchar(max)';
|
|
|
|
ColumnCompiler_Redshift.prototype.longblob = 'varchar(max)';
|
|
|
|
ColumnCompiler_Redshift.prototype.mediumblob = 'varchar(16777218)';
|
|
|
|
ColumnCompiler_Redshift.prototype.set = 'text';
|
|
|
|
ColumnCompiler_Redshift.prototype.text = 'varchar(max)';
|
|
|
|
ColumnCompiler_Redshift.prototype.tinyblob = 'varchar(256)';
|
|
|
|
ColumnCompiler_Redshift.prototype.uuid = 'char(36)';
|
|
|
|
ColumnCompiler_Redshift.prototype.varbinary = 'varchar(max)';
|
|
|
|
ColumnCompiler_Redshift.prototype.bigint = 'bigint';
|
|
|
|
ColumnCompiler_Redshift.prototype.bool = 'boolean';
|
|
|
|
ColumnCompiler_Redshift.prototype.double = 'double precision';
|
|
|
|
ColumnCompiler_Redshift.prototype.floating = 'real';
|
|
|
|
ColumnCompiler_Redshift.prototype.smallint = 'smallint';
|
|
|
|
ColumnCompiler_Redshift.prototype.tinyint = 'smallint';
|
2018-02-03 08:33:02 -05:00
|
|
|
|
2019-06-04 00:37:17 +02:00
|
|
|
module.exports = ColumnCompiler_Redshift;
|