Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit b8056412
authored
May 31, 2015
by
Ruben Bridgewater
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some data types in mssql and postgres
1 parent
073f1777
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
181 additions
and
64 deletions
lib/dialects/mssql/data-types.js
lib/dialects/mssql/index.js
lib/dialects/postgres/data-types.js
test/unit/sql/data-types.test.js
lib/dialects/mssql/data-types.js
View file @
b805641
...
...
@@ -18,6 +18,18 @@ STRING.prototype.toSql = function() {
}
};
var
TEXT
=
function
()
{
if
(
!
(
this
instanceof
TEXT
))
return
new
TEXT
();
BaseTypes
.
TEXT
.
apply
(
this
,
arguments
);
};
util
.
inherits
(
TEXT
,
BaseTypes
.
TEXT
);
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
return
'NVARCHAR(MAX)'
;
};
var
BOOLEAN
=
function
()
{
if
(
!
(
this
instanceof
BOOLEAN
))
return
new
BOOLEAN
();
BaseTypes
.
BOOLEAN
.
apply
(
this
,
arguments
);
...
...
@@ -68,13 +80,70 @@ DATE.prototype.toSql = function() {
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
=
{
BOOLEAN
:
BOOLEAN
,
STRING
:
STRING
,
TEXT
:
TEXT
,
BLOB
:
BLOB
,
UUID
:
UUID
,
DATE
:
DATE
,
NOW
:
NOW
NOW
:
NOW
,
INTEGER
:
INTEGER
,
BIGINT
:
BIGINT
,
REAL
:
REAL
,
FLOAT
:
FLOAT
};
_
.
forIn
(
module
.
exports
,
function
(
DataType
,
key
)
{
...
...
lib/dialects/mssql/index.js
View file @
b805641
...
...
@@ -45,7 +45,8 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support
parser
:
false
,
type
:
true
,
using
:
false
,
}
},
NUMERIC
:
true
});
MssqlDialect
.
prototype
.
Query
=
Query
;
...
...
lib/dialects/postgres/data-types.js
View file @
b805641
...
...
@@ -55,10 +55,10 @@ var INTEGER = function() {
BaseTypes
.
INTEGER
.
apply
(
this
,
arguments
);
// POSTGRES does not support any parameters for integer
this
.
_length
=
null
;
this
.
options
.
length
=
null
;
this
.
_unsigned
=
null
;
this
.
_zerofill
=
null
;
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
};
util
.
inherits
(
INTEGER
,
BaseTypes
.
INTEGER
);
...
...
@@ -67,10 +67,10 @@ var BIGINT = function() {
BaseTypes
.
BIGINT
.
apply
(
this
,
arguments
);
// POSTGRES does not support any parameters for bigint
this
.
_length
=
null
;
this
.
options
.
length
=
null
;
this
.
_unsigned
=
null
;
this
.
_zerofill
=
null
;
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
};
util
.
inherits
(
BIGINT
,
BaseTypes
.
BIGINT
);
...
...
@@ -79,10 +79,10 @@ var REAL = function() {
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
;
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
};
util
.
inherits
(
REAL
,
BaseTypes
.
REAL
);
...
...
@@ -91,10 +91,10 @@ var DOUBLE = function() {
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
;
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
};
util
.
inherits
(
DOUBLE
,
BaseTypes
.
DOUBLE
);
...
...
@@ -102,18 +102,18 @@ 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
;
// POSTGRES does only support lengths as parameter.
// Values between 1-24 result in REAL
// Values between 25-53 result in DOUBLE PRECISION
if
(
this
.
_decimals
)
{
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
}
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
};
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
);
...
...
test/unit/sql/data-types.test.js
View file @
b805641
...
...
@@ -41,6 +41,13 @@ 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
});
});
suite
(
'CHAR'
,
function
()
{
testsql
(
'CHAR'
,
DataTypes
.
CHAR
,
{
default
:
'CHAR(255)'
...
...
@@ -112,41 +119,48 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql
(
'INTEGER.UNSIGNED'
,
DataTypes
.
INTEGER
.
UNSIGNED
,
{
default
:
'INTEGER UNSIGNED'
,
postgres
:
'INTEGER'
postgres
:
'INTEGER'
,
mssql
:
'INTEGER'
});
testsql
(
'INTEGER.UNSIGNED.ZEROFILL'
,
DataTypes
.
INTEGER
.
UNSIGNED
.
ZEROFILL
,
{
default
:
'INTEGER UNSIGNED ZEROFILL'
,
postgres
:
'INTEGER'
postgres
:
'INTEGER'
,
mssql
:
'INTEGER'
});
testsql
(
'INTEGER(11)'
,
DataTypes
.
INTEGER
(
11
),
{
default
:
'INTEGER(11)'
,
postgres
:
'INTEGER'
postgres
:
'INTEGER'
,
mssql
:
'INTEGER'
});
testsql
(
'INTEGER(11).UNSIGNED'
,
DataTypes
.
INTEGER
(
11
).
UNSIGNED
,
{
default
:
'INTEGER(11) UNSIGNED'
,
sqlite
:
'INTEGER UNSIGNED(11)'
,
postgres
:
'INTEGER'
postgres
:
'INTEGER'
,
mssql
:
'INTEGER'
});
testsql
(
'INTEGER(11).UNSIGNED.ZEROFILL'
,
DataTypes
.
INTEGER
(
11
).
UNSIGNED
.
ZEROFILL
,
{
default
:
'INTEGER(11) UNSIGNED ZEROFILL'
,
sqlite
:
'INTEGER UNSIGNED ZEROFILL(11)'
,
postgres
:
'INTEGER'
postgres
:
'INTEGER'
,
mssql
:
'INTEGER'
});
testsql
(
'INTEGER(11).ZEROFILL'
,
DataTypes
.
INTEGER
(
11
).
ZEROFILL
,
{
default
:
'INTEGER(11) ZEROFILL'
,
sqlite
:
'INTEGER ZEROFILL(11)'
,
postgres
:
'INTEGER'
postgres
:
'INTEGER'
,
mssql
:
'INTEGER'
});
testsql
(
'INTEGER(11).ZEROFILL.UNSIGNED'
,
DataTypes
.
INTEGER
(
11
).
ZEROFILL
.
UNSIGNED
,
{
default
:
'INTEGER(11) UNSIGNED ZEROFILL'
,
sqlite
:
'INTEGER UNSIGNED ZEROFILL(11)'
,
postgres
:
'INTEGER'
postgres
:
'INTEGER'
,
mssql
:
'INTEGER'
});
});
...
...
@@ -157,41 +171,48 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql
(
'BIGINT.UNSIGNED'
,
DataTypes
.
BIGINT
.
UNSIGNED
,
{
default
:
'BIGINT UNSIGNED'
,
postgres
:
'BIGINT'
postgres
:
'BIGINT'
,
mssql
:
'BIGINT'
});
testsql
(
'BIGINT.UNSIGNED.ZEROFILL'
,
DataTypes
.
BIGINT
.
UNSIGNED
.
ZEROFILL
,
{
default
:
'BIGINT UNSIGNED ZEROFILL'
,
postgres
:
'BIGINT'
postgres
:
'BIGINT'
,
mssql
:
'BIGINT'
});
testsql
(
'BIGINT(11)'
,
DataTypes
.
BIGINT
(
11
),
{
default
:
'BIGINT(11)'
,
postgres
:
'BIGINT'
postgres
:
'BIGINT'
,
mssql
:
'BIGINT'
});
testsql
(
'BIGINT(11).UNSIGNED'
,
DataTypes
.
BIGINT
(
11
).
UNSIGNED
,
{
default
:
'BIGINT(11) UNSIGNED'
,
sqlite
:
'BIGINT UNSIGNED(11)'
,
postgres
:
'BIGINT'
postgres
:
'BIGINT'
,
mssql
:
'BIGINT'
});
testsql
(
'BIGINT(11).UNSIGNED.ZEROFILL'
,
DataTypes
.
BIGINT
(
11
).
UNSIGNED
.
ZEROFILL
,
{
default
:
'BIGINT(11) UNSIGNED ZEROFILL'
,
sqlite
:
'BIGINT UNSIGNED ZEROFILL(11)'
,
postgres
:
'BIGINT'
postgres
:
'BIGINT'
,
mssql
:
'BIGINT'
});
testsql
(
'BIGINT(11).ZEROFILL'
,
DataTypes
.
BIGINT
(
11
).
ZEROFILL
,
{
default
:
'BIGINT(11) ZEROFILL'
,
sqlite
:
'BIGINT ZEROFILL(11)'
,
postgres
:
'BIGINT'
postgres
:
'BIGINT'
,
mssql
:
'BIGINT'
});
testsql
(
'BIGINT(11).ZEROFILL.UNSIGNED'
,
DataTypes
.
BIGINT
(
11
).
ZEROFILL
.
UNSIGNED
,
{
default
:
'BIGINT(11) UNSIGNED ZEROFILL'
,
sqlite
:
'BIGINT UNSIGNED ZEROFILL(11)'
,
postgres
:
'BIGINT'
postgres
:
'BIGINT'
,
mssql
:
'BIGINT'
});
});
...
...
@@ -202,65 +223,76 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
testsql
(
'REAL.UNSIGNED'
,
DataTypes
.
REAL
.
UNSIGNED
,
{
default
:
'REAL UNSIGNED'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11)'
,
DataTypes
.
REAL
(
11
),
{
default
:
'REAL(11)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11).UNSIGNED'
,
DataTypes
.
REAL
(
11
).
UNSIGNED
,
{
default
:
'REAL(11) UNSIGNED'
,
sqlite
:
'REAL UNSIGNED(11)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11).UNSIGNED.ZEROFILL'
,
DataTypes
.
REAL
(
11
).
UNSIGNED
.
ZEROFILL
,
{
default
:
'REAL(11) UNSIGNED ZEROFILL'
,
sqlite
:
'REAL UNSIGNED ZEROFILL(11)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11).ZEROFILL'
,
DataTypes
.
REAL
(
11
).
ZEROFILL
,
{
default
:
'REAL(11) ZEROFILL'
,
sqlite
:
'REAL ZEROFILL(11)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11).ZEROFILL.UNSIGNED'
,
DataTypes
.
REAL
(
11
).
ZEROFILL
.
UNSIGNED
,
{
default
:
'REAL(11) UNSIGNED ZEROFILL'
,
sqlite
:
'REAL UNSIGNED ZEROFILL(11)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11, 12)'
,
DataTypes
.
REAL
(
11
,
12
),
{
default
:
'REAL(11,12)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11, 12).UNSIGNED'
,
DataTypes
.
REAL
(
11
,
12
).
UNSIGNED
,
{
default
:
'REAL(11,12) UNSIGNED'
,
sqlite
:
'REAL UNSIGNED(11,12)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11, 12).UNSIGNED.ZEROFILL'
,
DataTypes
.
REAL
(
11
,
12
).
UNSIGNED
.
ZEROFILL
,
{
default
:
'REAL(11,12) UNSIGNED ZEROFILL'
,
sqlite
:
'REAL UNSIGNED ZEROFILL(11,12)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11, 12).ZEROFILL'
,
DataTypes
.
REAL
(
11
,
12
).
ZEROFILL
,
{
default
:
'REAL(11,12) ZEROFILL'
,
sqlite
:
'REAL ZEROFILL(11,12)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
testsql
(
'REAL(11, 12).ZEROFILL.UNSIGNED'
,
DataTypes
.
REAL
(
11
,
12
).
ZEROFILL
.
UNSIGNED
,
{
default
:
'REAL(11,12) UNSIGNED ZEROFILL'
,
sqlite
:
'REAL UNSIGNED ZEROFILL(11,12)'
,
postgres
:
'REAL'
postgres
:
'REAL'
,
mssql
:
'REAL'
});
});
...
...
@@ -336,70 +368,81 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
suite
(
'FLOAT'
,
function
()
{
testsql
(
'FLOAT'
,
DataTypes
.
FLOAT
,
{
default
:
'FLOAT'
,
postgres
:
'
DOUBLE PRECISION
'
postgres
:
'
FLOAT
'
});
testsql
(
'FLOAT.UNSIGNED'
,
DataTypes
.
FLOAT
.
UNSIGNED
,
{
default
:
'FLOAT UNSIGNED'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT'
,
mssql
:
'FLOAT'
});
testsql
(
'FLOAT(11)'
,
DataTypes
.
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
,
{
default
:
'FLOAT(11) UNSIGNED'
,
sqlite
:
'FLOAT UNSIGNED(11)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT(11)'
,
mssql
:
'FLOAT(11)'
});
testsql
(
'FLOAT(11).UNSIGNED.ZEROFILL'
,
DataTypes
.
FLOAT
(
11
).
UNSIGNED
.
ZEROFILL
,
{
default
:
'FLOAT(11) UNSIGNED ZEROFILL'
,
sqlite
:
'FLOAT UNSIGNED ZEROFILL(11)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT(11)'
,
mssql
:
'FLOAT(11)'
});
testsql
(
'FLOAT(11).ZEROFILL'
,
DataTypes
.
FLOAT
(
11
).
ZEROFILL
,
{
default
:
'FLOAT(11) ZEROFILL'
,
sqlite
:
'FLOAT ZEROFILL(11)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT(11)'
,
mssql
:
'FLOAT(11)'
});
testsql
(
'FLOAT(11).ZEROFILL.UNSIGNED'
,
DataTypes
.
FLOAT
(
11
).
ZEROFILL
.
UNSIGNED
,
{
default
:
'FLOAT(11) UNSIGNED ZEROFILL'
,
sqlite
:
'FLOAT UNSIGNED ZEROFILL(11)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT(11)'
,
mssql
:
'FLOAT(11)'
});
testsql
(
'FLOAT(11, 12)'
,
DataTypes
.
FLOAT
(
11
,
12
),
{
default
:
'FLOAT(11,12)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT'
,
mssql
:
'FLOAT'
});
testsql
(
'FLOAT(11, 12).UNSIGNED'
,
DataTypes
.
FLOAT
(
11
,
12
).
UNSIGNED
,
{
default
:
'FLOAT(11,12) UNSIGNED'
,
sqlite
:
'FLOAT UNSIGNED(11,12)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT'
,
mssql
:
'FLOAT'
});
testsql
(
'FLOAT(11, 12).UNSIGNED.ZEROFILL'
,
DataTypes
.
FLOAT
(
11
,
12
).
UNSIGNED
.
ZEROFILL
,
{
default
:
'FLOAT(11,12) UNSIGNED ZEROFILL'
,
sqlite
:
'FLOAT UNSIGNED ZEROFILL(11,12)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT'
,
mssql
:
'FLOAT'
});
testsql
(
'FLOAT(11, 12).ZEROFILL'
,
DataTypes
.
FLOAT
(
11
,
12
).
ZEROFILL
,
{
default
:
'FLOAT(11,12) ZEROFILL'
,
sqlite
:
'FLOAT ZEROFILL(11,12)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT'
,
mssql
:
'FLOAT'
});
testsql
(
'FLOAT(11, 12).ZEROFILL.UNSIGNED'
,
DataTypes
.
FLOAT
(
11
,
12
).
ZEROFILL
.
UNSIGNED
,
{
default
:
'FLOAT(11,12) UNSIGNED ZEROFILL'
,
sqlite
:
'FLOAT UNSIGNED ZEROFILL(11,12)'
,
postgres
:
'DOUBLE PRECISION'
postgres
:
'FLOAT'
,
mssql
:
'FLOAT'
});
});
...
...
@@ -483,6 +526,10 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
postgres
:
'TIMESTAMP WITH TIME ZONE[]'
});
testsql
(
'ARRAY(BOOLEAN)'
,
DataTypes
.
ARRAY
(
DataTypes
.
BOOLEAN
),
{
postgres
:
'BOOLEAN[]'
});
testsql
(
'ARRAY(DECIMAL)'
,
DataTypes
.
ARRAY
(
DataTypes
.
DECIMAL
),
{
postgres
:
'DECIMAL[]'
});
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment