data-types.js
2.25 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
var BaseTypes = require('../../data-types')
, util = require('util')
, _ = require('lodash');
var STRING = function() {
if (!(this instanceof STRING)) return new STRING();
BaseTypes.STRING.apply(this, arguments);
};
util.inherits(STRING, BaseTypes.STRING);
STRING.prototype.toSql = function() {
if (this._binary) {
return 'BYTEA';
}
return BaseTypes.STRING.prototype.toSql.call(this);
};
var CHAR = function() {
if (!(this instanceof CHAR)) return new CHAR();
BaseTypes.CHAR.apply(this, arguments);
};
util.inherits(CHAR, BaseTypes.CHAR);
CHAR.prototype.toSql = function() {
if (this._binary) {
return 'BYTEA';
}
return BaseTypes.CHAR.prototype.toSql.call(this);
};
var BOOLEAN = function() {
if (!(this instanceof BOOLEAN)) return new BOOLEAN();
BaseTypes.BOOLEAN.apply(this, arguments);
};
util.inherits(BOOLEAN, BaseTypes.BOOLEAN);
BOOLEAN.prototype.toSql = function() {
return 'BOOLEAN';
};
var DATE = function() {
if (!(this instanceof DATE)) return new DATE();
BaseTypes.DATE.apply(this, arguments);
};
util.inherits(DATE, BaseTypes.DATE);
DATE.prototype.toSql = function() {
return 'TIMESTAMP WITH TIME ZONE';
};
var INTEGER = function() {
if (!(this instanceof INTEGER)) return new INTEGER();
BaseTypes.INTEGER.apply(this, arguments);
// POSTGRES does not support length on INTEGER
delete this._length;
delete this.options.length;
};
util.inherits(INTEGER, BaseTypes.INTEGER);
var BIGINT = function() {
if (!(this instanceof BIGINT)) return new BIGINT();
BaseTypes.BIGINT.apply(this, arguments);
// POSTGRES does not support length on BIGINT
delete this._length;
delete this.options.length;
};
util.inherits(BIGINT, BaseTypes.BIGINT);
var BLOB = function() {
if (!(this instanceof BLOB)) return new BLOB();
BaseTypes.BLOB.apply(this, arguments);
};
util.inherits(BLOB, BaseTypes.BLOB);
BLOB.prototype.toSql = function() {
return 'BYTEA';
};
module.exports = {
STRING: STRING,
CHAR: CHAR,
BOOLEAN: BOOLEAN,
DATE: DATE,
INTEGER: INTEGER,
BIGINT: BIGINT,
BLOB: BLOB
};
_.forIn(module.exports, function (DataType, key) {
if (!DataType.key) DataType.key = key;
if (!DataType.extend) {
DataType.extend = function(oldType) {
return new DataType(oldType.options);
};
}
});