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

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