不要怂,就是干,撸起袖子干!

Commit 3dd94d84 by Mick Hansen

Merge pull request #3615 from BridgeAR/master

Fixed a couple postgres type errors, new type unit tests and insert REAL...
2 parents a144c583 89cca907
......@@ -197,13 +197,12 @@ util.inherits(BIGINT, NUMBER);
BIGINT.prototype.key = BIGINT.key = 'BIGINT';
/**
* Floating point number. Accepts one or two arguments for precision
* Floating point number (4-byte precision). Accepts one or two arguments for precision
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property FLOAT
*/
var FLOAT = function(length, decimals) {
var options = typeof length === 'object' && length || {
length: length,
......@@ -217,6 +216,44 @@ util.inherits(FLOAT, NUMBER);
FLOAT.prototype.key = FLOAT.key = 'FLOAT';
/**
* Floating point number (4-byte precision). Accepts one or two arguments for precision
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property REAL
*/
var REAL = function(length, decimals) {
var options = typeof length === 'object' && length || {
length: length,
decimals: decimals
};
if (!(this instanceof REAL)) return new REAL(options);
NUMBER.call(this, options);
};
util.inherits(REAL, NUMBER);
REAL.prototype.key = REAL.key = 'REAL';
/**
* Floating point number (8-byte precision). Accepts one or two arguments for precision
*
* Available properties: `UNSIGNED`, `ZEROFILL`
*
* @property DOUBLE
*/
var DOUBLE = function(length, decimals) {
var options = typeof length === 'object' && length || {
length: length,
decimals: decimals
};
if (!(this instanceof DOUBLE)) return new DOUBLE(options);
NUMBER.call(this, options);
};
util.inherits(DOUBLE, NUMBER);
DOUBLE.prototype.key = DOUBLE.key = 'DOUBLE PRECISION';
/**
* Decimal number. Accepts one or two arguments for precision
*
* Available properties: `UNSIGNED`, `ZEROFILL`
......@@ -526,14 +563,14 @@ ARRAY.is = function(obj, type) {
return obj instanceof ARRAY && obj.type instanceof type;
};
var helpers = {
BINARY: [STRING, CHAR],
UNSIGNED: [NUMBER, INTEGER, BIGINT, FLOAT],
ZEROFILL: [NUMBER, INTEGER, BIGINT, FLOAT],
UNSIGNED: [NUMBER, INTEGER, BIGINT, FLOAT, DOUBLE, REAL],
ZEROFILL: [NUMBER, INTEGER, BIGINT, FLOAT, DOUBLE, REAL],
PRECISION: [DECIMAL],
SCALE: [DECIMAL]
};
Object.keys(helpers).forEach(function (helper) {
helpers[helper].forEach(function (DataType) {
if (!DataType[helper]) {
......@@ -566,6 +603,7 @@ module.exports = {
NOW: NOW,
BLOB: BLOB,
DECIMAL: DECIMAL,
NUMERIC: DECIMAL,
UUID: UUID,
UUIDV1: UUIDV1,
UUIDV4: UUIDV4,
......@@ -576,5 +614,8 @@ module.exports = {
ARRAY: ARRAY,
NONE: VIRTUAL,
ENUM: ENUM,
RANGE: RANGE
RANGE: RANGE,
REAL: REAL,
DOUBLE: DOUBLE,
'DOUBLE PRECISION': DOUBLE
};
......@@ -30,7 +30,8 @@ MysqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support
parser: true,
type: true,
using: 1,
}
},
NUMERIC: true
});
MysqlDialect.prototype.Query = Query;
......
......@@ -54,9 +54,11 @@ 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;
// POSTGRES does not support any parameters for integer
this._length = null;
this.options.length = null;
this._unsigned = null;
this._zerofill = null;
};
util.inherits(INTEGER, BaseTypes.INTEGER);
......@@ -64,12 +66,54 @@ 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;
// POSTGRES does not support any parameters for bigint
this._length = null;
this.options.length = null;
this._unsigned = null;
this._zerofill = null;
};
util.inherits(BIGINT, BaseTypes.BIGINT);
var REAL = function() {
if (!(this instanceof REAL)) return new REAL();
BaseTypes.REAL.apply(this, arguments);
// POSTGRES does not support any parameters for real
this._length = null;
this.options.length = null;
this._unsigned = null;
this._zerofill = null;
};
util.inherits(REAL, BaseTypes.REAL);
var DOUBLE = function() {
if (!(this instanceof DOUBLE)) return new DOUBLE();
BaseTypes.DOUBLE.apply(this, arguments);
// POSTGRES does not support any parameters for double
this._length = null;
this.options.length = null;
this._unsigned = null;
this._zerofill = null;
};
util.inherits(DOUBLE, BaseTypes.DOUBLE);
var FLOAT = function() {
if (!(this instanceof FLOAT)) return new FLOAT();
BaseTypes.FLOAT.apply(this, arguments);
// POSTGRES does not support any parameters for float
this._length = null;
this.options.length = null;
this._unsigned = null;
this._zerofill = null;
};
util.inherits(FLOAT, BaseTypes.FLOAT);
FLOAT.prototype.toSql = function() {
return 'DOUBLE PRECISION';
};
var BLOB = function() {
if (!(this instanceof BLOB)) return new BLOB();
BaseTypes.BLOB.apply(this, arguments);
......@@ -87,7 +131,10 @@ module.exports = {
DATE: DATE,
INTEGER: INTEGER,
BIGINT: BIGINT,
BLOB: BLOB
BLOB: BLOB,
REAL: REAL,
'DOUBLE PRECISION': DOUBLE,
FLOAT: FLOAT
};
_.forIn(module.exports, function (DataType, key) {
......
......@@ -27,7 +27,6 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp
'EXCEPTION': true,
'ON DUPLICATE KEY': false,
'ORDER NULLS': true,
'ARRAY': true,
returnValues: {
returning: true
},
......@@ -42,6 +41,8 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp
using: 2,
where: true
},
NUMERIC: true,
ARRAY: true,
JSON: true,
JSONB: true
});
......
......@@ -97,11 +97,41 @@ FLOAT.prototype.toSql = function() {
return NUMBER.prototype.toSql.call(this);
};
var DOUBLE = function(length, decimals) {
var options = typeof length === 'object' && length || {
length: length,
decimals: decimals
};
if (!(this instanceof DOUBLE)) return new DOUBLE(options);
NUMBER.call(this, options);
};
util.inherits(DOUBLE, BaseTypes.DOUBLE);
DOUBLE.prototype.key = DOUBLE.key = 'DOUBLE PRECISION';
DOUBLE.prototype.toSql = function() {
return NUMBER.prototype.toSql.call(this);
};
var REAL = function(length, decimals) {
var options = typeof length === 'object' && length || {
length: length,
decimals: decimals
};
if (!(this instanceof REAL)) return new REAL(options);
NUMBER.call(this, options);
};
util.inherits(REAL, BaseTypes.REAL);
REAL.prototype.key = REAL.key = 'REAL';
REAL.prototype.toSql = function() {
return NUMBER.prototype.toSql.call(this);
};
module.exports = {
STRING: STRING,
CHAR: CHAR,
NUMBER: NUMBER,
FLOAT: FLOAT,
REAL: REAL,
'DOUBLE PRECISION': DOUBLE,
INTEGER: INTEGER,
BIGINT: BIGINT
};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!