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 fcd07efb
authored
Oct 11, 2018
by
Sushant
Committed by
GitHub
Oct 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: cleanup integer option removal (#10021)
1 parent
b04c7900
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
40 deletions
lib/data-types.js
lib/dialects/mssql/data-types.js
lib/dialects/postgres/data-types.js
lib/dialects/sqlite/data-types.js
test/unit/dialects/mysql/query.test.js
test/unit/model/define.test.js
lib/data-types.js
View file @
fcd07ef
...
@@ -5,12 +5,13 @@ const inherits = require('./utils/inherits');
...
@@ -5,12 +5,13 @@ const inherits = require('./utils/inherits');
const
_
=
require
(
'lodash'
);
const
_
=
require
(
'lodash'
);
const
wkx
=
require
(
'wkx'
);
const
wkx
=
require
(
'wkx'
);
const
sequelizeErrors
=
require
(
'./errors'
);
const
sequelizeErrors
=
require
(
'./errors'
);
const
warnings
=
{};
const
Validator
=
require
(
'./utils/validator-extras'
).
validator
;
const
Validator
=
require
(
'./utils/validator-extras'
).
validator
;
const
momentTz
=
require
(
'moment-timezone'
);
const
momentTz
=
require
(
'moment-timezone'
);
const
moment
=
require
(
'moment'
);
const
moment
=
require
(
'moment'
);
const
logger
=
require
(
'./utils/logger'
);
const
logger
=
require
(
'./utils/logger'
);
const
warnings
=
{};
function
ABSTRACT
()
{}
function
ABSTRACT
()
{}
ABSTRACT
.
prototype
.
dialectTypes
=
''
;
ABSTRACT
.
prototype
.
dialectTypes
=
''
;
...
@@ -24,7 +25,7 @@ ABSTRACT.prototype.toSql = function toSql() {
...
@@ -24,7 +25,7 @@ ABSTRACT.prototype.toSql = function toSql() {
ABSTRACT
.
warn
=
function
warn
(
link
,
text
)
{
ABSTRACT
.
warn
=
function
warn
(
link
,
text
)
{
if
(
!
warnings
[
text
])
{
if
(
!
warnings
[
text
])
{
warnings
[
text
]
=
true
;
warnings
[
text
]
=
true
;
logger
.
warn
(
`
${
text
}
, '\n>> Check:',
${
link
}
`
);
logger
.
warn
(
`
${
text
}
\n>> Check:
${
link
}
`
);
}
}
};
};
ABSTRACT
.
prototype
.
stringify
=
function
stringify
(
value
,
options
)
{
ABSTRACT
.
prototype
.
stringify
=
function
stringify
(
value
,
options
)
{
...
...
lib/dialects/mssql/data-types.js
View file @
fcd07ef
...
@@ -8,6 +8,21 @@ module.exports = BaseTypes => {
...
@@ -8,6 +8,21 @@ module.exports = BaseTypes => {
const
warn
=
BaseTypes
.
ABSTRACT
.
warn
.
bind
(
undefined
,
'https://msdn.microsoft.com/en-us/library/ms187752%28v=sql.110%29.aspx'
);
const
warn
=
BaseTypes
.
ABSTRACT
.
warn
.
bind
(
undefined
,
'https://msdn.microsoft.com/en-us/library/ms187752%28v=sql.110%29.aspx'
);
/**
/**
* Removes unsupported MSSQL options, i.e., LENGTH, UNSIGNED and ZEROFILL, for the integer data types.
* @param dataType The base integer data type.
* @private
*/
function
removeUnsupportedIntegerOptions
(
dataType
)
{
if
(
dataType
.
_length
||
dataType
.
options
.
length
||
dataType
.
_unsigned
||
dataType
.
_zerofill
)
{
warn
(
`MSSQL does not support '
${
dataType
.
key
}
' with options. Plain '
${
dataType
.
key
}
' will be used instead.`
);
dataType
.
_length
=
undefined
;
dataType
.
options
.
length
=
undefined
;
dataType
.
_unsigned
=
undefined
;
dataType
.
_zerofill
=
undefined
;
}
}
/**
* types: [hex, ...]
* types: [hex, ...]
* @see hex here https://github.com/tediousjs/tedious/blob/master/src/data-type.js
* @see hex here https://github.com/tediousjs/tedious/blob/master/src/data-type.js
*/
*/
...
@@ -155,14 +170,7 @@ module.exports = BaseTypes => {
...
@@ -155,14 +170,7 @@ module.exports = BaseTypes => {
if
(
!
(
this
instanceof
INTEGER
))
return
new
INTEGER
(
length
);
if
(
!
(
this
instanceof
INTEGER
))
return
new
INTEGER
(
length
);
BaseTypes
.
INTEGER
.
apply
(
this
,
arguments
);
BaseTypes
.
INTEGER
.
apply
(
this
,
arguments
);
// MSSQL does not support any options for integer
removeUnsupportedIntegerOptions
(
this
);
if
(
this
.
_length
||
this
.
options
.
length
||
this
.
_unsigned
||
this
.
_zerofill
)
{
warn
(
'MSSQL does not support INTEGER with options. Plain `INTEGER` will be used instead.'
);
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
}
}
}
inherits
(
INTEGER
,
BaseTypes
.
INTEGER
);
inherits
(
INTEGER
,
BaseTypes
.
INTEGER
);
...
@@ -170,29 +178,14 @@ module.exports = BaseTypes => {
...
@@ -170,29 +178,14 @@ module.exports = BaseTypes => {
if
(
!
(
this
instanceof
TINYINT
))
return
new
TINYINT
(
length
);
if
(
!
(
this
instanceof
TINYINT
))
return
new
TINYINT
(
length
);
BaseTypes
.
TINYINT
.
apply
(
this
,
arguments
);
BaseTypes
.
TINYINT
.
apply
(
this
,
arguments
);
// MSSQL does not support any options for tinyint
removeUnsupportedIntegerOptions
(
this
);
if
(
this
.
_length
||
this
.
options
.
length
||
this
.
_unsigned
||
this
.
_zerofill
)
{
warn
(
'MSSQL does not support TINYINT with options. Plain `TINYINT` will be used instead.'
);
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
}
}
}
inherits
(
TINYINT
,
BaseTypes
.
TINYINT
);
inherits
(
TINYINT
,
BaseTypes
.
TINYINT
);
function
SMALLINT
(
length
)
{
function
SMALLINT
(
length
)
{
if
(
!
(
this
instanceof
SMALLINT
))
return
new
SMALLINT
(
length
);
if
(
!
(
this
instanceof
SMALLINT
))
return
new
SMALLINT
(
length
);
BaseTypes
.
SMALLINT
.
apply
(
this
,
arguments
);
BaseTypes
.
SMALLINT
.
apply
(
this
,
arguments
);
removeUnsupportedIntegerOptions
(
this
);
// MSSQL does not support any options for smallint
if
(
this
.
_length
||
this
.
options
.
length
||
this
.
_unsigned
||
this
.
_zerofill
)
{
warn
(
'MSSQL does not support SMALLINT with options. Plain `SMALLINT` will be used instead.'
);
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
}
}
}
inherits
(
SMALLINT
,
BaseTypes
.
SMALLINT
);
inherits
(
SMALLINT
,
BaseTypes
.
SMALLINT
);
...
@@ -200,14 +193,7 @@ module.exports = BaseTypes => {
...
@@ -200,14 +193,7 @@ module.exports = BaseTypes => {
if
(
!
(
this
instanceof
BIGINT
))
return
new
BIGINT
(
length
);
if
(
!
(
this
instanceof
BIGINT
))
return
new
BIGINT
(
length
);
BaseTypes
.
BIGINT
.
apply
(
this
,
arguments
);
BaseTypes
.
BIGINT
.
apply
(
this
,
arguments
);
// MSSQL does not support any options for bigint
removeUnsupportedIntegerOptions
(
this
);
if
(
this
.
_length
||
this
.
options
.
length
||
this
.
_unsigned
||
this
.
_zerofill
)
{
warn
(
'MSSQL does not support BIGINT with options. Plain `BIGINT` will be used instead.'
);
this
.
_length
=
undefined
;
this
.
options
.
length
=
undefined
;
this
.
_unsigned
=
undefined
;
this
.
_zerofill
=
undefined
;
}
}
}
inherits
(
BIGINT
,
BaseTypes
.
BIGINT
);
inherits
(
BIGINT
,
BaseTypes
.
BIGINT
);
...
...
lib/dialects/postgres/data-types.js
View file @
fcd07ef
...
@@ -10,10 +10,11 @@ module.exports = BaseTypes => {
...
@@ -10,10 +10,11 @@ module.exports = BaseTypes => {
/**
/**
* Removes unsupported Postgres options, i.e., LENGTH, UNSIGNED and ZEROFILL, for the integer data types.
* Removes unsupported Postgres options, i.e., LENGTH, UNSIGNED and ZEROFILL, for the integer data types.
* @param dataType The base integer data type.
* @param dataType The base integer data type.
* @private
*/
*/
function
removeUnsupportedIntegerOptions
(
dataType
)
{
function
removeUnsupportedIntegerOptions
(
dataType
)
{
if
(
dataType
.
_length
||
dataType
.
options
.
length
||
dataType
.
_unsigned
||
dataType
.
_zerofill
)
{
if
(
dataType
.
_length
||
dataType
.
options
.
length
||
dataType
.
_unsigned
||
dataType
.
_zerofill
)
{
warn
(
'PostgresSQL does not support '
+
dataType
.
_name
+
' with LENGTH, UNSIGNED or ZEROFILL. Plain `'
+
dataType
.
_name
+
'` will be used instead.'
);
warn
(
`PostgresSQL does not support '
${
dataType
.
key
}
' with LENGTH, UNSIGNED or ZEROFILL. Plain '
${
dataType
.
key
}
' will be used instead.`
);
dataType
.
_length
=
undefined
;
dataType
.
_length
=
undefined
;
dataType
.
options
.
length
=
undefined
;
dataType
.
options
.
length
=
undefined
;
dataType
.
_unsigned
=
undefined
;
dataType
.
_unsigned
=
undefined
;
...
...
lib/dialects/sqlite/data-types.js
View file @
fcd07ef
...
@@ -9,10 +9,11 @@ module.exports = BaseTypes => {
...
@@ -9,10 +9,11 @@ module.exports = BaseTypes => {
/**
/**
* Removes unsupported SQLite options, i.e., UNSIGNED and ZEROFILL, for the integer data types.
* Removes unsupported SQLite options, i.e., UNSIGNED and ZEROFILL, for the integer data types.
* @param dataType The base integer data type.
* @param dataType The base integer data type.
* @private
*/
*/
function
removeUnsupportedIntegerOptions
(
dataType
)
{
function
removeUnsupportedIntegerOptions
(
dataType
)
{
if
(
dataType
.
_zerofill
||
dataType
.
_unsigned
)
{
if
(
dataType
.
_zerofill
||
dataType
.
_unsigned
)
{
warn
(
'SQLite does not support '
+
dataType
.
_name
+
' with UNSIGNED or ZEROFILL. Plain `'
+
dataType
.
_name
+
'` will be used instead.'
);
warn
(
`SQLite does not support '
${
dataType
.
key
}
' with UNSIGNED or ZEROFILL. Plain '
${
dataType
.
key
}
' will be used instead.`
);
dataType
.
_unsigned
=
undefined
;
dataType
.
_unsigned
=
undefined
;
dataType
.
_zerofill
=
undefined
;
dataType
.
_zerofill
=
undefined
;
}
}
...
...
test/unit/dialects/mysql/query.test.js
View file @
fcd07ef
...
@@ -22,8 +22,8 @@ describe('[MYSQL Specific] Query', () => {
...
@@ -22,8 +22,8 @@ describe('[MYSQL Specific] Query', () => {
it
(
'check iterable'
,
()
=>
{
it
(
'check iterable'
,
()
=>
{
const
validWarning
=
[];
const
validWarning
=
[];
const
invalidWarning
=
{};
const
invalidWarning
=
{};
const
warnings
=
[
validWarning
,
undefined
,
invalidWarning
];
const
warnings
=
[
validWarning
,
undefined
,
invalidWarning
];
const
query
=
new
Query
({},
current
,
{});
const
query
=
new
Query
({},
current
,
{});
const
stub
=
sinon
.
stub
(
query
,
'run'
);
const
stub
=
sinon
.
stub
(
query
,
'run'
);
stub
.
onFirstCall
().
resolves
(
warnings
);
stub
.
onFirstCall
().
resolves
(
warnings
);
...
...
test/unit/model/define.test.js
View file @
fcd07ef
...
@@ -4,7 +4,9 @@ const chai = require('chai'),
...
@@ -4,7 +4,9 @@ const chai = require('chai'),
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Support
=
require
(
'../support'
),
Support
=
require
(
'../support'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
DataTypes
=
require
(
'../../../lib/data-types'
),
current
=
Support
.
sequelize
;
sinon
=
require
(
'sinon'
),
current
=
Support
.
sequelize
,
dialect
=
Support
.
getTestDialect
();
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
describe
(
Support
.
getTestDialectTeaser
(
'Model'
),
()
=>
{
describe
(
'define'
,
()
=>
{
describe
(
'define'
,
()
=>
{
...
@@ -98,5 +100,30 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -98,5 +100,30 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
}).
to
.
throw
(
'Invalid definition for "part.name", "notNull" validator is only allowed with "allowNull:false"'
);
}).
to
.
throw
(
'Invalid definition for "part.name", "notNull" validator is only allowed with "allowNull:false"'
);
});
});
describe
(
'datatype warnings'
,
()
=>
{
beforeEach
(()
=>
{
sinon
.
spy
(
console
,
'warn'
);
});
afterEach
(()
=>
{
console
.
warn
.
restore
();
});
it
(
'warn for unsupported INTEGER options'
,
()
=>
{
current
.
define
(
'A'
,
{
age
:
{
type
:
DataTypes
.
TINYINT
.
UNSIGNED
}
});
if
(
dialect
===
'postgres'
||
dialect
===
'sqlite'
||
dialect
===
'mssql'
)
{
expect
(
true
).
to
.
equal
(
console
.
warn
.
calledOnce
);
expect
(
console
.
warn
.
args
[
0
][
0
]).
to
.
contain
(
"does not support 'TINYINT'"
);
}
else
{
expect
(
false
).
to
.
equal
(
console
.
warn
.
calledOnce
);
}
});
});
});
});
});
});
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