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

Commit 8a6c1a5f by Mick Hansen

Merge pull request #3836 from BridgeAR/fix-types

Fix some data types in mssql and postgres
2 parents a92fb9ce db6531dc
# Next # Next
- [FEATURE] Add support for keyword `after` in options of a field (useful for migrations), only for MySQL. [#3166](https://github.com/sequelize/sequelize/pull/3166) - [FEATURE] Add support for keyword `after` in options of a field (useful for migrations), only for MySQL. [#3166](https://github.com/sequelize/sequelize/pull/3166)
- [FEATURE] There's a new sequelize.truncate function to truncate all tables defined through the sequelize models [#2671](https://github.com/sequelize/sequelize/pull/2671) - [FEATURE] There's a new sequelize.truncate function to truncate all tables defined through the sequelize models [#2671](https://github.com/sequelize/sequelize/pull/2671)
- [FEATURE] Add support for MySQLs TINYTEXT, MEDIUMTEXT and LONGTEXT. [#3836](https://github.com/sequelize/sequelize/pull/3836)
- [FIXED] Fix a case where `type` in `sequelize.query` was not being set to raw. [#3800](https://github.com/sequelize/sequelize/pull/3800) - [FIXED] Fix a case where `type` in `sequelize.query` was not being set to raw. [#3800](https://github.com/sequelize/sequelize/pull/3800)
- [FIXED] Fix an issue where include all was not being properly expanded for self-references [#3804](https://github.com/sequelize/sequelize/issues/3804) - [FIXED] Fix an issue where include all was not being properly expanded for self-references [#3804](https://github.com/sequelize/sequelize/issues/3804)
- [FIXED] Fix instance.changed regression to not return false negatives for not changed null values [#3812](https://github.com/sequelize/sequelize/issues/3812) - [FIXED] Fix instance.changed regression to not return false negatives for not changed null values [#3812](https://github.com/sequelize/sequelize/issues/3812)
......
...@@ -101,18 +101,32 @@ CHAR.prototype.toSql = function() { ...@@ -101,18 +101,32 @@ CHAR.prototype.toSql = function() {
return 'CHAR(' + this._length + ')' + ((this._binary) ? ' BINARY' : ''); return 'CHAR(' + this._length + ')' + ((this._binary) ? ' BINARY' : '');
}; };
/** /**
* An unlimited length text column * An (un)limited length text column. Available lengths: `tiny`, `medium`, `long`
* @property TEXT * @property TEXT
*/ */
var TEXT = function(options) { var TEXT = function(length) {
var options = typeof length === 'object' && length || {
length: length
};
if (!(this instanceof TEXT)) return new TEXT(options); if (!(this instanceof TEXT)) return new TEXT(options);
this._length = options.length || '';
}; };
util.inherits(TEXT, ABSTRACT); util.inherits(TEXT, ABSTRACT);
TEXT.prototype.key = TEXT.key = 'TEXT'; TEXT.prototype.key = TEXT.key = 'TEXT';
TEXT.prototype.toSql = function() {
switch (this._length.toLowerCase()) {
case 'tiny':
return 'TINYTEXT';
case 'medium':
return 'MEDIUMTEXT';
case 'long':
return 'LONGTEXT';
default:
return this.key;
}
};
var NUMBER = function(options) { var NUMBER = function(options) {
this.options = options; this.options = options;
......
...@@ -18,6 +18,15 @@ STRING.prototype.toSql = function() { ...@@ -18,6 +18,15 @@ STRING.prototype.toSql = function() {
} }
}; };
BaseTypes.TEXT.prototype.toSql = function() {
// TEXT is deprecated in mssql and it would normally be saved as a non-unicode string.
// Using unicode is just future proof
if (this._length.toLowerCase() === 'tiny') {
return 'NVARCHAR(256)'; // tiny text should be 2^8 < 8000
}
return 'NVARCHAR(MAX)';
};
var BOOLEAN = function() { var BOOLEAN = function() {
if (!(this instanceof BOOLEAN)) return new BOOLEAN(); if (!(this instanceof BOOLEAN)) return new BOOLEAN();
BaseTypes.BOOLEAN.apply(this, arguments); BaseTypes.BOOLEAN.apply(this, arguments);
...@@ -28,13 +37,10 @@ BOOLEAN.prototype.toSql = function() { ...@@ -28,13 +37,10 @@ BOOLEAN.prototype.toSql = function() {
return 'BIT'; return 'BIT';
}; };
var BLOB = function() { BaseTypes.BLOB.prototype.toSql = function() {
if (!(this instanceof BLOB)) return new BLOB(); if (this._length.toLowerCase() === 'tiny') {
BaseTypes.BLOB.apply(this, arguments); return 'VARBINARY(256)'; // tiny blobs should be 2^8 < 8000
}; }
util.inherits(BLOB, BaseTypes.BLOB);
BLOB.prototype.toSql = function() {
return 'VARBINARY(MAX)'; return 'VARBINARY(MAX)';
}; };
...@@ -68,13 +74,68 @@ DATE.prototype.toSql = function() { ...@@ -68,13 +74,68 @@ DATE.prototype.toSql = function() {
return 'DATETIME2'; return 'DATETIME2';
}; };
var INTEGER = function() {
if (!(this instanceof INTEGER)) return new INTEGER();
BaseTypes.INTEGER.apply(this, arguments);
// MSSQL does not support any parameters for integer
this._length = undefined;
this.options.length = undefined;
this._unsigned = undefined;
this._zerofill = undefined;
};
util.inherits(INTEGER, BaseTypes.INTEGER);
var BIGINT = function() {
if (!(this instanceof BIGINT)) return new BIGINT();
BaseTypes.BIGINT.apply(this, arguments);
// MSSQL does not support any parameters for bigint
this._length = undefined;
this.options.length = undefined;
this._unsigned = undefined;
this._zerofill = undefined;
};
util.inherits(BIGINT, BaseTypes.BIGINT);
var REAL = function() {
if (!(this instanceof REAL)) return new REAL();
BaseTypes.REAL.apply(this, arguments);
// MSSQL does not support any parameters for real
this._length = undefined;
this.options.length = undefined;
this._unsigned = undefined;
this._zerofill = undefined;
};
util.inherits(REAL, BaseTypes.REAL);
var FLOAT = function() {
if (!(this instanceof FLOAT)) return new FLOAT();
BaseTypes.FLOAT.apply(this, arguments);
// MSSQL does only support lengths as parameter.
// Values between 1-24 result in 7 digits precision (4 bytes storage size)
// Values between 25-53 result in 15 digits precision (8 bytes storage size)
if (this._decimals) {
this._length = undefined;
this.options.length = undefined;
}
this._unsigned = undefined;
this._zerofill = undefined;
};
util.inherits(FLOAT, BaseTypes.FLOAT);
module.exports = { module.exports = {
BOOLEAN: BOOLEAN, BOOLEAN: BOOLEAN,
STRING: STRING, STRING: STRING,
BLOB: BLOB,
UUID: UUID, UUID: UUID,
DATE: DATE, DATE: DATE,
NOW: NOW NOW: NOW,
INTEGER: INTEGER,
BIGINT: BIGINT,
REAL: REAL,
FLOAT: FLOAT
}; };
_.forIn(module.exports, function (DataType, key) { _.forIn(module.exports, function (DataType, key) {
......
...@@ -45,7 +45,8 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support ...@@ -45,7 +45,8 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support
parser: false, parser: false,
type: true, type: true,
using: false, using: false,
} },
NUMERIC: true
}); });
MssqlDialect.prototype.Query = Query; MssqlDialect.prototype.Query = Query;
......
...@@ -17,6 +17,10 @@ STRING.prototype.toSql = function() { ...@@ -17,6 +17,10 @@ STRING.prototype.toSql = function() {
return BaseTypes.STRING.prototype.toSql.call(this); return BaseTypes.STRING.prototype.toSql.call(this);
}; };
BaseTypes.TEXT.prototype.toSql = function() {
return 'TEXT';
};
var CHAR = function() { var CHAR = function() {
if (!(this instanceof CHAR)) return new CHAR(); if (!(this instanceof CHAR)) return new CHAR();
BaseTypes.CHAR.apply(this, arguments); BaseTypes.CHAR.apply(this, arguments);
...@@ -55,10 +59,10 @@ var INTEGER = function() { ...@@ -55,10 +59,10 @@ var INTEGER = function() {
BaseTypes.INTEGER.apply(this, arguments); BaseTypes.INTEGER.apply(this, arguments);
// POSTGRES does not support any parameters for integer // POSTGRES does not support any parameters for integer
this._length = null; this._length = undefined;
this.options.length = null; this.options.length = undefined;
this._unsigned = null; this._unsigned = undefined;
this._zerofill = null; this._zerofill = undefined;
}; };
util.inherits(INTEGER, BaseTypes.INTEGER); util.inherits(INTEGER, BaseTypes.INTEGER);
...@@ -67,10 +71,10 @@ var BIGINT = function() { ...@@ -67,10 +71,10 @@ var BIGINT = function() {
BaseTypes.BIGINT.apply(this, arguments); BaseTypes.BIGINT.apply(this, arguments);
// POSTGRES does not support any parameters for bigint // POSTGRES does not support any parameters for bigint
this._length = null; this._length = undefined;
this.options.length = null; this.options.length = undefined;
this._unsigned = null; this._unsigned = undefined;
this._zerofill = null; this._zerofill = undefined;
}; };
util.inherits(BIGINT, BaseTypes.BIGINT); util.inherits(BIGINT, BaseTypes.BIGINT);
...@@ -79,10 +83,10 @@ var REAL = function() { ...@@ -79,10 +83,10 @@ var REAL = function() {
BaseTypes.REAL.apply(this, arguments); BaseTypes.REAL.apply(this, arguments);
// POSTGRES does not support any parameters for real // POSTGRES does not support any parameters for real
this._length = null; this._length = undefined;
this.options.length = null; this.options.length = undefined;
this._unsigned = null; this._unsigned = undefined;
this._zerofill = null; this._zerofill = undefined;
}; };
util.inherits(REAL, BaseTypes.REAL); util.inherits(REAL, BaseTypes.REAL);
...@@ -91,10 +95,10 @@ var DOUBLE = function() { ...@@ -91,10 +95,10 @@ var DOUBLE = function() {
BaseTypes.DOUBLE.apply(this, arguments); BaseTypes.DOUBLE.apply(this, arguments);
// POSTGRES does not support any parameters for double // POSTGRES does not support any parameters for double
this._length = null; this._length = undefined;
this.options.length = null; this.options.length = undefined;
this._unsigned = null; this._unsigned = undefined;
this._zerofill = null; this._zerofill = undefined;
}; };
util.inherits(DOUBLE, BaseTypes.DOUBLE); util.inherits(DOUBLE, BaseTypes.DOUBLE);
...@@ -102,25 +106,20 @@ var FLOAT = function() { ...@@ -102,25 +106,20 @@ var FLOAT = function() {
if (!(this instanceof FLOAT)) return new FLOAT(); if (!(this instanceof FLOAT)) return new FLOAT();
BaseTypes.FLOAT.apply(this, arguments); BaseTypes.FLOAT.apply(this, arguments);
// POSTGRES does not support any parameters for float // POSTGRES does only support lengths as parameter.
this._length = null; // Values between 1-24 result in REAL
this.options.length = null; // Values between 25-53 result in DOUBLE PRECISION
this._unsigned = null; if (this._decimals) {
this._zerofill = null; this._length = undefined;
this.options.length = undefined;
this._decimals = undefined;
}
this._unsigned = undefined;
this._zerofill = undefined;
}; };
util.inherits(FLOAT, BaseTypes.FLOAT); util.inherits(FLOAT, BaseTypes.FLOAT);
FLOAT.prototype.toSql = function() { BaseTypes.BLOB.prototype.toSql = function() {
return 'DOUBLE PRECISION';
};
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'; return 'BYTEA';
}; };
...@@ -131,7 +130,6 @@ module.exports = { ...@@ -131,7 +130,6 @@ module.exports = {
DATE: DATE, DATE: DATE,
INTEGER: INTEGER, INTEGER: INTEGER,
BIGINT: BIGINT, BIGINT: BIGINT,
BLOB: BLOB,
REAL: REAL, REAL: REAL,
'DOUBLE PRECISION': DOUBLE, 'DOUBLE PRECISION': DOUBLE,
FLOAT: FLOAT FLOAT: FLOAT
......
...@@ -18,6 +18,10 @@ STRING.prototype.toSql = function() { ...@@ -18,6 +18,10 @@ STRING.prototype.toSql = function() {
} }
}; };
BaseTypes.TEXT.prototype.toSql = function() {
return 'TEXT';
};
var CHAR = function() { var CHAR = function() {
if (!(this instanceof CHAR)) return new CHAR(); if (!(this instanceof CHAR)) return new CHAR();
BaseTypes.CHAR.apply(this, arguments); BaseTypes.CHAR.apply(this, arguments);
......
...@@ -26,6 +26,11 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -26,6 +26,11 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
mssql: 'NVARCHAR(1234)' mssql: 'NVARCHAR(1234)'
}); });
testsql('STRING({ length: 1234 })', DataTypes.STRING({ length: 1234 }), {
default: 'VARCHAR(1234)',
mssql: 'NVARCHAR(1234)'
});
testsql('STRING(1234).BINARY', DataTypes.STRING(1234).BINARY, { testsql('STRING(1234).BINARY', DataTypes.STRING(1234).BINARY, {
default: 'VARCHAR(1234) BINARY', default: 'VARCHAR(1234) BINARY',
sqlite: 'VARCHAR BINARY(1234)', sqlite: 'VARCHAR BINARY(1234)',
...@@ -41,6 +46,41 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -41,6 +46,41 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
}); });
}); });
suite('TEXT', function () {
testsql('TEXT', DataTypes.TEXT, {
default: 'TEXT',
mssql: 'NVARCHAR(MAX)' // in mssql text is actually representing a non unicode text field
});
testsql('TEXT("tiny")', DataTypes.TEXT('tiny'), {
default: 'TEXT',
mssql: 'NVARCHAR(256)',
mysql: 'TINYTEXT',
mariadb: 'TINYTEXT'
});
testsql('TEXT({ length: "tiny" })', DataTypes.TEXT({ length: 'tiny' }), {
default: 'TEXT',
mssql: 'NVARCHAR(256)',
mysql: 'TINYTEXT',
mariadb: 'TINYTEXT'
});
testsql('TEXT("medium")', DataTypes.TEXT('medium'), {
default: 'TEXT',
mssql: 'NVARCHAR(MAX)',
mysql: 'MEDIUMTEXT',
mariadb: 'MEDIUMTEXT'
});
testsql('TEXT("long")', DataTypes.TEXT('long'), {
default: 'TEXT',
mssql: 'NVARCHAR(MAX)',
mysql: 'LONGTEXT',
mariadb: 'LONGTEXT'
});
});
suite('CHAR', function () { suite('CHAR', function () {
testsql('CHAR', DataTypes.CHAR, { testsql('CHAR', DataTypes.CHAR, {
default: 'CHAR(255)' default: 'CHAR(255)'
...@@ -50,6 +90,10 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -50,6 +90,10 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default: 'CHAR(12)' default: 'CHAR(12)'
}); });
testsql('CHAR({ length: 12 })', DataTypes.CHAR({ length: 12 }), {
default: 'CHAR(12)'
});
testsql('CHAR(12).BINARY', DataTypes.CHAR(12).BINARY, { testsql('CHAR(12).BINARY', DataTypes.CHAR(12).BINARY, {
default: 'CHAR(12) BINARY', default: 'CHAR(12) BINARY',
sqlite: 'CHAR BINARY(12)', sqlite: 'CHAR BINARY(12)',
...@@ -112,41 +156,54 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -112,41 +156,54 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql('INTEGER.UNSIGNED', DataTypes.INTEGER.UNSIGNED, { testsql('INTEGER.UNSIGNED', DataTypes.INTEGER.UNSIGNED, {
default: 'INTEGER UNSIGNED', default: 'INTEGER UNSIGNED',
postgres: 'INTEGER' postgres: 'INTEGER',
mssql: 'INTEGER'
}); });
testsql('INTEGER.UNSIGNED.ZEROFILL', DataTypes.INTEGER.UNSIGNED.ZEROFILL, { testsql('INTEGER.UNSIGNED.ZEROFILL', DataTypes.INTEGER.UNSIGNED.ZEROFILL, {
default: 'INTEGER UNSIGNED ZEROFILL', default: 'INTEGER UNSIGNED ZEROFILL',
postgres: 'INTEGER' postgres: 'INTEGER',
mssql: 'INTEGER'
}); });
testsql('INTEGER(11)', DataTypes.INTEGER(11), { testsql('INTEGER(11)', DataTypes.INTEGER(11), {
default: 'INTEGER(11)', default: 'INTEGER(11)',
postgres: 'INTEGER' postgres: 'INTEGER',
mssql: 'INTEGER'
});
testsql('INTEGER({ length: 11 })', DataTypes.INTEGER({ length: 11 }), {
default: 'INTEGER(11)',
postgres: 'INTEGER',
mssql: 'INTEGER'
}); });
testsql('INTEGER(11).UNSIGNED', DataTypes.INTEGER(11).UNSIGNED, { testsql('INTEGER(11).UNSIGNED', DataTypes.INTEGER(11).UNSIGNED, {
default: 'INTEGER(11) UNSIGNED', default: 'INTEGER(11) UNSIGNED',
sqlite: 'INTEGER UNSIGNED(11)', sqlite: 'INTEGER UNSIGNED(11)',
postgres: 'INTEGER' postgres: 'INTEGER',
mssql: 'INTEGER'
}); });
testsql('INTEGER(11).UNSIGNED.ZEROFILL', DataTypes.INTEGER(11).UNSIGNED.ZEROFILL, { testsql('INTEGER(11).UNSIGNED.ZEROFILL', DataTypes.INTEGER(11).UNSIGNED.ZEROFILL, {
default: 'INTEGER(11) UNSIGNED ZEROFILL', default: 'INTEGER(11) UNSIGNED ZEROFILL',
sqlite: 'INTEGER UNSIGNED ZEROFILL(11)', sqlite: 'INTEGER UNSIGNED ZEROFILL(11)',
postgres: 'INTEGER' postgres: 'INTEGER',
mssql: 'INTEGER'
}); });
testsql('INTEGER(11).ZEROFILL', DataTypes.INTEGER(11).ZEROFILL, { testsql('INTEGER(11).ZEROFILL', DataTypes.INTEGER(11).ZEROFILL, {
default: 'INTEGER(11) ZEROFILL', default: 'INTEGER(11) ZEROFILL',
sqlite: 'INTEGER ZEROFILL(11)', sqlite: 'INTEGER ZEROFILL(11)',
postgres: 'INTEGER' postgres: 'INTEGER',
mssql: 'INTEGER'
}); });
testsql('INTEGER(11).ZEROFILL.UNSIGNED', DataTypes.INTEGER(11).ZEROFILL.UNSIGNED, { testsql('INTEGER(11).ZEROFILL.UNSIGNED', DataTypes.INTEGER(11).ZEROFILL.UNSIGNED, {
default: 'INTEGER(11) UNSIGNED ZEROFILL', default: 'INTEGER(11) UNSIGNED ZEROFILL',
sqlite: 'INTEGER UNSIGNED ZEROFILL(11)', sqlite: 'INTEGER UNSIGNED ZEROFILL(11)',
postgres: 'INTEGER' postgres: 'INTEGER',
mssql: 'INTEGER'
}); });
}); });
...@@ -157,41 +214,54 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -157,41 +214,54 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql('BIGINT.UNSIGNED', DataTypes.BIGINT.UNSIGNED, { testsql('BIGINT.UNSIGNED', DataTypes.BIGINT.UNSIGNED, {
default: 'BIGINT UNSIGNED', default: 'BIGINT UNSIGNED',
postgres: 'BIGINT' postgres: 'BIGINT',
mssql: 'BIGINT'
}); });
testsql('BIGINT.UNSIGNED.ZEROFILL', DataTypes.BIGINT.UNSIGNED.ZEROFILL, { testsql('BIGINT.UNSIGNED.ZEROFILL', DataTypes.BIGINT.UNSIGNED.ZEROFILL, {
default: 'BIGINT UNSIGNED ZEROFILL', default: 'BIGINT UNSIGNED ZEROFILL',
postgres: 'BIGINT' postgres: 'BIGINT',
mssql: 'BIGINT'
}); });
testsql('BIGINT(11)', DataTypes.BIGINT(11), { testsql('BIGINT(11)', DataTypes.BIGINT(11), {
default: 'BIGINT(11)', default: 'BIGINT(11)',
postgres: 'BIGINT' postgres: 'BIGINT',
mssql: 'BIGINT'
});
testsql('BIGINT({ length: 11 })', DataTypes.BIGINT({ length: 11 }), {
default: 'BIGINT(11)',
postgres: 'BIGINT',
mssql: 'BIGINT'
}); });
testsql('BIGINT(11).UNSIGNED', DataTypes.BIGINT(11).UNSIGNED, { testsql('BIGINT(11).UNSIGNED', DataTypes.BIGINT(11).UNSIGNED, {
default: 'BIGINT(11) UNSIGNED', default: 'BIGINT(11) UNSIGNED',
sqlite: 'BIGINT UNSIGNED(11)', sqlite: 'BIGINT UNSIGNED(11)',
postgres: 'BIGINT' postgres: 'BIGINT',
mssql: 'BIGINT'
}); });
testsql('BIGINT(11).UNSIGNED.ZEROFILL', DataTypes.BIGINT(11).UNSIGNED.ZEROFILL, { testsql('BIGINT(11).UNSIGNED.ZEROFILL', DataTypes.BIGINT(11).UNSIGNED.ZEROFILL, {
default: 'BIGINT(11) UNSIGNED ZEROFILL', default: 'BIGINT(11) UNSIGNED ZEROFILL',
sqlite: 'BIGINT UNSIGNED ZEROFILL(11)', sqlite: 'BIGINT UNSIGNED ZEROFILL(11)',
postgres: 'BIGINT' postgres: 'BIGINT',
mssql: 'BIGINT'
}); });
testsql('BIGINT(11).ZEROFILL', DataTypes.BIGINT(11).ZEROFILL, { testsql('BIGINT(11).ZEROFILL', DataTypes.BIGINT(11).ZEROFILL, {
default: 'BIGINT(11) ZEROFILL', default: 'BIGINT(11) ZEROFILL',
sqlite: 'BIGINT ZEROFILL(11)', sqlite: 'BIGINT ZEROFILL(11)',
postgres: 'BIGINT' postgres: 'BIGINT',
mssql: 'BIGINT'
}); });
testsql('BIGINT(11).ZEROFILL.UNSIGNED', DataTypes.BIGINT(11).ZEROFILL.UNSIGNED, { testsql('BIGINT(11).ZEROFILL.UNSIGNED', DataTypes.BIGINT(11).ZEROFILL.UNSIGNED, {
default: 'BIGINT(11) UNSIGNED ZEROFILL', default: 'BIGINT(11) UNSIGNED ZEROFILL',
sqlite: 'BIGINT UNSIGNED ZEROFILL(11)', sqlite: 'BIGINT UNSIGNED ZEROFILL(11)',
postgres: 'BIGINT' postgres: 'BIGINT',
mssql: 'BIGINT'
}); });
}); });
...@@ -202,65 +272,89 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -202,65 +272,89 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql('REAL.UNSIGNED', DataTypes.REAL.UNSIGNED, { testsql('REAL.UNSIGNED', DataTypes.REAL.UNSIGNED, {
default: 'REAL UNSIGNED', default: 'REAL UNSIGNED',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11)', DataTypes.REAL(11), { testsql('REAL(11)', DataTypes.REAL(11), {
default: 'REAL(11)', default: 'REAL(11)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
});
testsql('REAL({ length: 11 })', DataTypes.REAL({ length: 11 }), {
default: 'REAL(11)',
postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11).UNSIGNED', DataTypes.REAL(11).UNSIGNED, { testsql('REAL(11).UNSIGNED', DataTypes.REAL(11).UNSIGNED, {
default: 'REAL(11) UNSIGNED', default: 'REAL(11) UNSIGNED',
sqlite: 'REAL UNSIGNED(11)', sqlite: 'REAL UNSIGNED(11)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11).UNSIGNED.ZEROFILL', DataTypes.REAL(11).UNSIGNED.ZEROFILL, { testsql('REAL(11).UNSIGNED.ZEROFILL', DataTypes.REAL(11).UNSIGNED.ZEROFILL, {
default: 'REAL(11) UNSIGNED ZEROFILL', default: 'REAL(11) UNSIGNED ZEROFILL',
sqlite: 'REAL UNSIGNED ZEROFILL(11)', sqlite: 'REAL UNSIGNED ZEROFILL(11)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11).ZEROFILL', DataTypes.REAL(11).ZEROFILL, { testsql('REAL(11).ZEROFILL', DataTypes.REAL(11).ZEROFILL, {
default: 'REAL(11) ZEROFILL', default: 'REAL(11) ZEROFILL',
sqlite: 'REAL ZEROFILL(11)', sqlite: 'REAL ZEROFILL(11)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11).ZEROFILL.UNSIGNED', DataTypes.REAL(11).ZEROFILL.UNSIGNED, { testsql('REAL(11).ZEROFILL.UNSIGNED', DataTypes.REAL(11).ZEROFILL.UNSIGNED, {
default: 'REAL(11) UNSIGNED ZEROFILL', default: 'REAL(11) UNSIGNED ZEROFILL',
sqlite: 'REAL UNSIGNED ZEROFILL(11)', sqlite: 'REAL UNSIGNED ZEROFILL(11)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11, 12)', DataTypes.REAL(11, 12), { testsql('REAL(11, 12)', DataTypes.REAL(11, 12), {
default: 'REAL(11,12)', default: 'REAL(11,12)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11, 12).UNSIGNED', DataTypes.REAL(11, 12).UNSIGNED, { testsql('REAL(11, 12).UNSIGNED', DataTypes.REAL(11, 12).UNSIGNED, {
default: 'REAL(11,12) UNSIGNED', default: 'REAL(11,12) UNSIGNED',
sqlite: 'REAL UNSIGNED(11,12)', sqlite: 'REAL UNSIGNED(11,12)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
});
testsql('REAL({ length: 11, decimals: 12 }).UNSIGNED', DataTypes.REAL({ length: 11, decimals: 12 }).UNSIGNED, {
default: 'REAL(11,12) UNSIGNED',
sqlite: 'REAL UNSIGNED(11,12)',
postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11, 12).UNSIGNED.ZEROFILL', DataTypes.REAL(11, 12).UNSIGNED.ZEROFILL, { testsql('REAL(11, 12).UNSIGNED.ZEROFILL', DataTypes.REAL(11, 12).UNSIGNED.ZEROFILL, {
default: 'REAL(11,12) UNSIGNED ZEROFILL', default: 'REAL(11,12) UNSIGNED ZEROFILL',
sqlite: 'REAL UNSIGNED ZEROFILL(11,12)', sqlite: 'REAL UNSIGNED ZEROFILL(11,12)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11, 12).ZEROFILL', DataTypes.REAL(11, 12).ZEROFILL, { testsql('REAL(11, 12).ZEROFILL', DataTypes.REAL(11, 12).ZEROFILL, {
default: 'REAL(11,12) ZEROFILL', default: 'REAL(11,12) ZEROFILL',
sqlite: 'REAL ZEROFILL(11,12)', sqlite: 'REAL ZEROFILL(11,12)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
testsql('REAL(11, 12).ZEROFILL.UNSIGNED', DataTypes.REAL(11, 12).ZEROFILL.UNSIGNED, { testsql('REAL(11, 12).ZEROFILL.UNSIGNED', DataTypes.REAL(11, 12).ZEROFILL.UNSIGNED, {
default: 'REAL(11,12) UNSIGNED ZEROFILL', default: 'REAL(11,12) UNSIGNED ZEROFILL',
sqlite: 'REAL UNSIGNED ZEROFILL(11,12)', sqlite: 'REAL UNSIGNED ZEROFILL(11,12)',
postgres: 'REAL' postgres: 'REAL',
mssql: 'REAL'
}); });
}); });
...@@ -285,6 +379,12 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -285,6 +379,12 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
postgres: 'DOUBLE PRECISION' postgres: 'DOUBLE PRECISION'
}); });
testsql('DOUBLE({ length: 11 }).UNSIGNED', DataTypes.DOUBLE({ length: 11 }).UNSIGNED, {
default: 'DOUBLE PRECISION(11) UNSIGNED',
sqlite: 'DOUBLE PRECISION UNSIGNED(11)',
postgres: 'DOUBLE PRECISION'
});
testsql('DOUBLE(11).UNSIGNED.ZEROFILL', DataTypes.DOUBLE(11).UNSIGNED.ZEROFILL, { testsql('DOUBLE(11).UNSIGNED.ZEROFILL', DataTypes.DOUBLE(11).UNSIGNED.ZEROFILL, {
default: 'DOUBLE PRECISION(11) UNSIGNED ZEROFILL', default: 'DOUBLE PRECISION(11) UNSIGNED ZEROFILL',
sqlite: 'DOUBLE PRECISION UNSIGNED ZEROFILL(11)', sqlite: 'DOUBLE PRECISION UNSIGNED ZEROFILL(11)',
...@@ -336,70 +436,95 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -336,70 +436,95 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
suite('FLOAT', function () { suite('FLOAT', function () {
testsql('FLOAT', DataTypes.FLOAT, { testsql('FLOAT', DataTypes.FLOAT, {
default: 'FLOAT', default: 'FLOAT',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT'
}); });
testsql('FLOAT.UNSIGNED', DataTypes.FLOAT.UNSIGNED, { testsql('FLOAT.UNSIGNED', DataTypes.FLOAT.UNSIGNED, {
default: 'FLOAT UNSIGNED', default: 'FLOAT UNSIGNED',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT',
mssql: 'FLOAT'
}); });
testsql('FLOAT(11)', DataTypes.FLOAT(11), { testsql('FLOAT(11)', DataTypes.FLOAT(11), {
default: 'FLOAT(11)', default: 'FLOAT(11)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT(11)', // 1-24 = 4 bytes; 35-53 = 8 bytes
mssql: 'FLOAT(11)' // 1-24 = 4 bytes; 35-53 = 8 bytes
}); });
testsql('FLOAT(11).UNSIGNED', DataTypes.FLOAT(11).UNSIGNED, { testsql('FLOAT(11).UNSIGNED', DataTypes.FLOAT(11).UNSIGNED, {
default: 'FLOAT(11) UNSIGNED', default: 'FLOAT(11) UNSIGNED',
sqlite: 'FLOAT UNSIGNED(11)', sqlite: 'FLOAT UNSIGNED(11)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT(11)',
mssql: 'FLOAT(11)'
}); });
testsql('FLOAT(11).UNSIGNED.ZEROFILL', DataTypes.FLOAT(11).UNSIGNED.ZEROFILL, { testsql('FLOAT(11).UNSIGNED.ZEROFILL', DataTypes.FLOAT(11).UNSIGNED.ZEROFILL, {
default: 'FLOAT(11) UNSIGNED ZEROFILL', default: 'FLOAT(11) UNSIGNED ZEROFILL',
sqlite: 'FLOAT UNSIGNED ZEROFILL(11)', sqlite: 'FLOAT UNSIGNED ZEROFILL(11)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT(11)',
mssql: 'FLOAT(11)'
}); });
testsql('FLOAT(11).ZEROFILL', DataTypes.FLOAT(11).ZEROFILL, { testsql('FLOAT(11).ZEROFILL', DataTypes.FLOAT(11).ZEROFILL, {
default: 'FLOAT(11) ZEROFILL', default: 'FLOAT(11) ZEROFILL',
sqlite: 'FLOAT ZEROFILL(11)', sqlite: 'FLOAT ZEROFILL(11)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT(11)',
mssql: 'FLOAT(11)'
});
testsql('FLOAT({ length: 11 }).ZEROFILL', DataTypes.FLOAT({ length: 11 }).ZEROFILL, {
default: 'FLOAT(11) ZEROFILL',
sqlite: 'FLOAT ZEROFILL(11)',
postgres: 'FLOAT(11)',
mssql: 'FLOAT(11)'
}); });
testsql('FLOAT(11).ZEROFILL.UNSIGNED', DataTypes.FLOAT(11).ZEROFILL.UNSIGNED, { testsql('FLOAT(11).ZEROFILL.UNSIGNED', DataTypes.FLOAT(11).ZEROFILL.UNSIGNED, {
default: 'FLOAT(11) UNSIGNED ZEROFILL', default: 'FLOAT(11) UNSIGNED ZEROFILL',
sqlite: 'FLOAT UNSIGNED ZEROFILL(11)', sqlite: 'FLOAT UNSIGNED ZEROFILL(11)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT(11)',
mssql: 'FLOAT(11)'
}); });
testsql('FLOAT(11, 12)', DataTypes.FLOAT(11, 12), { testsql('FLOAT(11, 12)', DataTypes.FLOAT(11, 12), {
default: 'FLOAT(11,12)', default: 'FLOAT(11,12)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT',
mssql: 'FLOAT'
}); });
testsql('FLOAT(11, 12).UNSIGNED', DataTypes.FLOAT(11, 12).UNSIGNED, { testsql('FLOAT(11, 12).UNSIGNED', DataTypes.FLOAT(11, 12).UNSIGNED, {
default: 'FLOAT(11,12) UNSIGNED', default: 'FLOAT(11,12) UNSIGNED',
sqlite: 'FLOAT UNSIGNED(11,12)', sqlite: 'FLOAT UNSIGNED(11,12)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT',
mssql: 'FLOAT'
});
testsql('FLOAT({ length: 11, decimals: 12 }).UNSIGNED', DataTypes.FLOAT({ length: 11, decimals: 12 }).UNSIGNED, {
default: 'FLOAT(11,12) UNSIGNED',
sqlite: 'FLOAT UNSIGNED(11,12)',
postgres: 'FLOAT',
mssql: 'FLOAT'
}); });
testsql('FLOAT(11, 12).UNSIGNED.ZEROFILL', DataTypes.FLOAT(11, 12).UNSIGNED.ZEROFILL, { testsql('FLOAT(11, 12).UNSIGNED.ZEROFILL', DataTypes.FLOAT(11, 12).UNSIGNED.ZEROFILL, {
default: 'FLOAT(11,12) UNSIGNED ZEROFILL', default: 'FLOAT(11,12) UNSIGNED ZEROFILL',
sqlite: 'FLOAT UNSIGNED ZEROFILL(11,12)', sqlite: 'FLOAT UNSIGNED ZEROFILL(11,12)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT',
mssql: 'FLOAT'
}); });
testsql('FLOAT(11, 12).ZEROFILL', DataTypes.FLOAT(11, 12).ZEROFILL, { testsql('FLOAT(11, 12).ZEROFILL', DataTypes.FLOAT(11, 12).ZEROFILL, {
default: 'FLOAT(11,12) ZEROFILL', default: 'FLOAT(11,12) ZEROFILL',
sqlite: 'FLOAT ZEROFILL(11,12)', sqlite: 'FLOAT ZEROFILL(11,12)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT',
mssql: 'FLOAT'
}); });
testsql('FLOAT(11, 12).ZEROFILL.UNSIGNED', DataTypes.FLOAT(11, 12).ZEROFILL.UNSIGNED, { testsql('FLOAT(11, 12).ZEROFILL.UNSIGNED', DataTypes.FLOAT(11, 12).ZEROFILL.UNSIGNED, {
default: 'FLOAT(11,12) UNSIGNED ZEROFILL', default: 'FLOAT(11,12) UNSIGNED ZEROFILL',
sqlite: 'FLOAT UNSIGNED ZEROFILL(11,12)', sqlite: 'FLOAT UNSIGNED ZEROFILL(11,12)',
postgres: 'DOUBLE PRECISION' postgres: 'FLOAT',
mssql: 'FLOAT'
}); });
}); });
...@@ -422,9 +547,17 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -422,9 +547,17 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default: 'DECIMAL(10,2)' default: 'DECIMAL(10,2)'
}); });
testsql('DECIMAL({ precision: 10, scale: 2 })', DataTypes.DECIMAL({ precision: 10, scale: 2 }), {
default: 'DECIMAL(10,2)'
});
testsql('DECIMAL(10)', DataTypes.DECIMAL(10), { testsql('DECIMAL(10)', DataTypes.DECIMAL(10), {
default: 'DECIMAL(10)' default: 'DECIMAL(10)'
}); });
testsql('DECIMAL({ precision: 10 })', DataTypes.DECIMAL({ precision: 10 }), {
default: 'DECIMAL(10)'
});
}); });
suite('BLOB', function () { suite('BLOB', function () {
...@@ -434,19 +567,25 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -434,19 +567,25 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
postgres: 'BYTEA' postgres: 'BYTEA'
}); });
testsql('BLOB(\'tiny\')', DataTypes.BLOB('tiny'), { testsql('BLOB("tiny")', DataTypes.BLOB('tiny'), {
default: 'TINYBLOB', default: 'TINYBLOB',
mssql: 'VARBINARY(256)',
postgres: 'BYTEA'
});
testsql('BLOB("medium")', DataTypes.BLOB('medium'), {
default: 'MEDIUMBLOB',
mssql: 'VARBINARY(MAX)', mssql: 'VARBINARY(MAX)',
postgres: 'BYTEA' postgres: 'BYTEA'
}); });
testsql('BLOB(\'medium\')', DataTypes.BLOB('medium'), { testsql('BLOB({ length: "medium" })', DataTypes.BLOB({ length: 'medium' }), {
default: 'MEDIUMBLOB', default: 'MEDIUMBLOB',
mssql: 'VARBINARY(MAX)', mssql: 'VARBINARY(MAX)',
postgres: 'BYTEA' postgres: 'BYTEA'
}); });
testsql('BLOB(\'long\')', DataTypes.BLOB('long'), { testsql('BLOB("long")', DataTypes.BLOB('long'), {
default: 'LONGBLOB', default: 'LONGBLOB',
mssql: 'VARBINARY(MAX)', mssql: 'VARBINARY(MAX)',
postgres: 'BYTEA' postgres: 'BYTEA'
...@@ -483,6 +622,10 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -483,6 +622,10 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
postgres: 'TIMESTAMP WITH TIME ZONE[]' postgres: 'TIMESTAMP WITH TIME ZONE[]'
}); });
testsql('ARRAY(BOOLEAN)', DataTypes.ARRAY(DataTypes.BOOLEAN), {
postgres: 'BOOLEAN[]'
});
testsql('ARRAY(DECIMAL)', DataTypes.ARRAY(DataTypes.DECIMAL), { testsql('ARRAY(DECIMAL)', DataTypes.ARRAY(DataTypes.DECIMAL), {
postgres: 'DECIMAL[]' postgres: 'DECIMAL[]'
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!