-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
redshift-columncompiler.js
67 lines (58 loc) · 2.3 KB
/
redshift-columncompiler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Redshift Column Compiler
// -------
const ColumnCompiler_PG = require('../../postgres/schema/pg-columncompiler');
const ColumnCompiler = require('../../../schema/columncompiler');
class ColumnCompiler_Redshift extends ColumnCompiler_PG {
constructor() {
super(...arguments);
}
// Types:
// ------
bit(column) {
return column.length !== false ? `char(${column.length})` : 'char(1)';
}
datetime(without) {
return without ? 'timestamp' : 'timestamptz';
}
timestamp(without) {
return without ? 'timestamp' : 'timestamptz';
}
// Modifiers:
// ------
comment(comment) {
this.pushAdditional(function () {
this.pushQuery(
`comment on column ${this.tableCompiler.tableName()}.` +
this.formatter.wrap(this.args[0]) +
' is ' +
(comment ? `'${comment}'` : 'NULL')
);
}, comment);
}
}
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';
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 = ColumnCompiler.prototype.uuid;
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';
module.exports = ColumnCompiler_Redshift;