Repository navigation
8336 Adds support for postgres infinity timestamp - #8357
Conversation
…etters, and comparators.
|
@mkaufmaner, thanks for your PR! By analyzing the history of the files in this pull request, we identified @felixfbecker, @sushantdhiman and @janmeier to be potential reviewers. |
…e methods of DATE.
|
Please review! Increase coverage by 0.05%! Woot! Please note, this WON'T affect user defined setters. I think a major refactor of data types should go into v5. |
sushantdhiman
left a comment
There was a problem hiding this comment.
_isChanged approach LGTM. Also model level changed and sanitize store is a good idea as well.
I have a few comments about duplicate logic, please address them.
Its a good first step to cleanup datatypes and will of-course fix that Infinity/-Infinity issue with Postgres
| }; | ||
|
|
||
| DATE.prototype._isChanged = function _isChanged(value, originalValue) { | ||
| if (originalValue && !!value && value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime()) { |
There was a problem hiding this comment.
Multi line this condition check
| DATEONLY.prototype._isChanged = function _isChanged(value, originalValue) { | ||
| if ( | ||
| originalValue && !!value && | ||
| (value === originalValue || value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime()) |
There was a problem hiding this comment.
move this to base type? this logic should be honored by all dialects for DATEONLY
| DATE.prototype._isChanged = function _isChanged(value, originalValue) { | ||
| if ( | ||
| originalValue && !!value && | ||
| (value === originalValue || value instanceof Date && originalValue instanceof Date && value.getTime() === originalValue.getTime()) |
There was a problem hiding this comment.
This logic is again same Postgres.DATEONLY._isChanged (which I have suggested to move to BaseTypes.DATEONLY)
May be BaseType.DATE should have this logic, BaseType.DATEONLY should call that and dialect would never need to override it
There was a problem hiding this comment.
The only reason I extended this into postgres was because it was the only dialect where the originalValue and value could be equal (Infinity === Infinity). All others would be Date.getTime() === Date.getTime().
However, after some thought I think you are right in moving it into the BaseType.
|
@sushantdhiman I will address these in the morning. Thanks for the quick response! |
…ded tests to improve coverage.
|
This is ready to go. Please finalize reviews :) |
ffa9788 to
866f448
Compare
| return 'BOOLEAN'; | ||
| }; | ||
|
|
||
| BOOLEAN.prototype._sanitize = function _sanitize(value) { |
There was a problem hiding this comment.
Why boolean is needed here, its logic looks exactly same as base type
There was a problem hiding this comment.
Where value === 'f' or 't'.
| @@ -34,6 +34,38 @@ module.exports = BaseTypes => { | |||
| inherits(DATEONLY, BaseTypes.DATEONLY); | |||
|
|
|||
| DATEONLY.parse = function parse(value) { | |||
There was a problem hiding this comment.
DATEONLY shares exact methods with DATE (from same dialect). I would say just call DATE.* methods inside DATEONLY as they both are same date types
sushantdhiman
left a comment
There was a problem hiding this comment.
LGTM, for solving postgres specific Infinity / -Infinity logic.
But it wont close #8356 , So please remove that issue from description.
|
@sushantdhiman Changed "Close #8356" to "See #8356". Also removed DATEONLY.parse entirely. |
|
@sushantdhiman Im not at my normal development environment at the moment but will fix the dateonly in about 7 hours when I wake up. |
…ta-types-api # Conflicts: # lib/model.js
|
@sushantdhiman @janmeier I have put back the DATEONLY.parse method; DATEONLY.parse = function parse(value) {
if (value === 'infinity') {
value = Infinity;
} else if (value === '-infinity') {
value = -Infinity;
}
return value;
};because the parser types differ from the DATE data type. DATEONLY: BaseTypes.DATEONLY.types.postgres = {
oids: [1082],
array_oids: [1182]
};DATE: BaseTypes.DATE.types.postgres = {
oids: [1184],
array_oids: [1185]
};If I change the DATEONLY oids then it will break existing functionality supporting varchar columns. |
1346971 to
071daf5
Compare
| }); | ||
|
|
||
| if (current.dialect.name === 'postgres') { | ||
| describe('GEOGRAPHY(POLYGON, SRID)', () => { |
There was a problem hiding this comment.
I don't see any code changes related to this - tests for something else?
There was a problem hiding this comment.
@janmeier Yes, I decided to add some tests to cover GEOGRAPHY types while I was at it because I wanted to increase coverage of the postgres dialect. Hope this doesn't prevent anything.
There was a problem hiding this comment.
Not at all, just wanted to make sure I wasn't missing anything
|
|
||
| DATEONLY.prototype._sanitize = function _sanitize(value, options) { | ||
| if (!options || options && !options.raw) { | ||
| return moment(value).format('YYYY-MM-DD'); |
There was a problem hiding this comment.
I think this is missing a !!value check. Now, we are getting "Invalid date" value for NULL, resulting in an error.
Pull Request check-list
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Closes #8336
See #8356 (Partial fix still requires further work)
See #8339