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

Commit f333d295 by Lewis Sobotkiewicz

feat(datatypes) Support fractional DATETIME columns in MySQL 5.6+, fixes #4205

1 parent e0a1d7b8
...@@ -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() {
......
...@@ -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');
}; };
......
...@@ -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();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!