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 f333d295
authored
Nov 12, 2015
by
Lewis Sobotkiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(datatypes) Support fractional DATETIME columns in MySQL 5.6+, fixes #4205
1 parent
e0a1d7b8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
lib/data-types.js
lib/dialects/mysql/data-types.js
test/unit/sql/data-types.test.js
lib/data-types.js
View file @
f333d29
...
@@ -410,7 +410,16 @@ TIME.prototype.toSql = function() {
...
@@ -410,7 +410,16 @@ TIME.prototype.toSql = function() {
* A datetime column
* A datetime column
* @property DATE
* @property DATE
*/
*/
var
DATE
=
ABSTRACT
.
inherits
();
var
DATE
=
ABSTRACT
.
inherits
(
function
(
length
)
{
var
options
=
typeof
length
===
'object'
&&
length
||
{
length
:
length
};
if
(
!
(
this
instanceof
DATE
))
return
new
DATE
(
options
);
this
.
options
=
options
;
this
.
_length
=
options
.
length
||
''
;
});
DATE
.
prototype
.
key
=
DATE
.
key
=
'DATE'
;
DATE
.
prototype
.
key
=
DATE
.
key
=
'DATE'
;
DATE
.
prototype
.
toSql
=
function
()
{
DATE
.
prototype
.
toSql
=
function
()
{
...
...
lib/dialects/mysql/data-types.js
View file @
f333d29
...
@@ -25,9 +25,17 @@ module.exports = function (BaseTypes) {
...
@@ -25,9 +25,17 @@ module.exports = function (BaseTypes) {
var
DATE
=
BaseTypes
.
DATE
.
inherits
();
var
DATE
=
BaseTypes
.
DATE
.
inherits
();
DATE
.
prototype
.
toSql
=
function
()
{
return
'DATETIME'
+
(
this
.
_length
?
'('
+
this
.
_length
+
')'
:
''
);
};
DATE
.
prototype
.
$stringify
=
function
(
date
,
options
)
{
DATE
.
prototype
.
$stringify
=
function
(
date
,
options
)
{
date
=
BaseTypes
.
DATE
.
prototype
.
$applyTimezone
(
date
,
options
);
// Fractional DATETIMEs only supported on MySQL 5.6.4+
if
(
this
.
_length
)
{
return
BaseTypes
.
DATE
.
prototype
.
$stringify
(
date
,
options
);
}
date
=
BaseTypes
.
DATE
.
prototype
.
$applyTimezone
(
date
,
options
);
return
date
.
format
(
'YYYY-MM-DD HH:mm:ss'
);
return
date
.
format
(
'YYYY-MM-DD HH:mm:ss'
);
};
};
...
...
test/unit/sql/data-types.test.js
View file @
f333d29
...
@@ -174,6 +174,13 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
...
@@ -174,6 +174,13 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
sqlite
:
'DATETIME'
sqlite
:
'DATETIME'
});
});
testsql
(
'DATE(6)'
,
DataTypes
.
DATE
(
6
),
{
postgres
:
'TIMESTAMP WITH TIME ZONE'
,
mssql
:
'DATETIME2'
,
mysql
:
'DATETIME(6)'
,
sqlite
:
'DATETIME'
});
suite
(
'validate'
,
function
()
{
suite
(
'validate'
,
function
()
{
test
(
'should throw an error if `value` is invalid'
,
function
()
{
test
(
'should throw an error if `value` is invalid'
,
function
()
{
var
type
=
DataTypes
.
DATE
();
var
type
=
DataTypes
.
DATE
();
...
...
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