Merge pull request #179 from azatoth/zero_datetime
Add special handling of zero date/time entries
This commit is contained in:
commit
5fec12a00c
10
lib/mysql.js
10
lib/mysql.js
|
@ -408,7 +408,15 @@ MySQL.prototype.fromColumnValue = function(prop, val) {
|
|||
val = String(val);
|
||||
break;
|
||||
case 'Date':
|
||||
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
|
||||
|
||||
// MySQL allows, unless NO_ZERO_DATE is set, dummy date/time entries
|
||||
// new Date() will return Invalid Date for those, so we need to handle
|
||||
// those separate.
|
||||
if (val == '0000-00-00 00:00:00') {
|
||||
val = null;
|
||||
} else {
|
||||
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
|
||||
}
|
||||
break;
|
||||
case 'Boolean':
|
||||
val = Boolean(val);
|
||||
|
|
|
@ -338,6 +338,23 @@ describe('migrations', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should map zero dateTime into null', function (done) {
|
||||
|
||||
query('INSERT INTO `DateData` ' +
|
||||
'(`dateTime`, `timestamp`) ' +
|
||||
'VALUES("0000-00-00 00:00:00", "0000-00-00 00:00:00") ',
|
||||
function (err, ret) {
|
||||
should.not.exists(err);
|
||||
DateData.findById(ret.insertId, function (err, dateData) {
|
||||
should(dateData.dateTime)
|
||||
.be.null();
|
||||
should(dateData.timestamp)
|
||||
.be.null();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should report errors for automigrate', function() {
|
||||
db.automigrate('XYZ', function(err) {
|
||||
assert(err);
|
||||
|
|
Loading…
Reference in New Issue