@balena/odata-to-abstract-sql
Advanced tools
Comparing version 5.4.3-date-compares-with-date-trunc-1fbea7c4974d959b0f58791126aeba80b161904e to 5.4.3-date-compares-with-date-trunc-98a6492c0001ad90cf434d1bc3e2f9330fbbdb9f
@@ -7,5 +7,5 @@ # Change Log | ||
## 5.4.3 - 2021-07-28 | ||
## 5.4.3 - 2021-08-24 | ||
* Add SBVR Date TIme Type to DateTrunc Wrapper [fisehara] | ||
* Add SBVR Date TIme Type to DateTrunc Wrapper JS Date format has only milliseconds precision, postgresql stores TIMESTAMPS with microseconds precission. Comparisions may fail, when giving millisecond JS dates but comparing on microseconds. [fisehara] | ||
@@ -12,0 +12,0 @@ ## 5.4.2 - 2021-06-30 |
@@ -825,12 +825,10 @@ "use strict"; | ||
else { | ||
let fieldDefinition; | ||
const mapping = this.ResourceMapping(prop.resource); | ||
if (mapping[prop.name]) { | ||
const fieldDefinition = _.find(prop.resource.fields, { | ||
fieldName: mapping[prop.name][1], | ||
}); | ||
if ((fieldDefinition === null || fieldDefinition === void 0 ? void 0 : fieldDefinition.dataType) === 'Date Time' || | ||
(fieldDefinition === null || fieldDefinition === void 0 ? void 0 : fieldDefinition.dataType) === 'Date') { | ||
fieldDefinition = prop.resource.fields.find((f) => f.fieldName === mapping[prop.name][1]); | ||
if ((fieldDefinition === null || fieldDefinition === void 0 ? void 0 : fieldDefinition.dataType) === 'Date Time') { | ||
return [ | ||
'DateTrunc', | ||
['Text', 'milliseconds'], | ||
['EmbeddedText', 'milliseconds'], | ||
this.ReferencedField(prop.resource, prop.name), | ||
@@ -837,0 +835,0 @@ ]; |
{ | ||
"name": "@balena/odata-to-abstract-sql", | ||
"version": "5.4.3-date-compares-with-date-trunc-1fbea7c4974d959b0f58791126aeba80b161904e", | ||
"version": "5.4.3-date-compares-with-date-trunc-98a6492c0001ad90cf434d1bc3e2f9330fbbdb9f", | ||
"description": "A consumer of the OData parser, written in OMeta", | ||
@@ -20,3 +20,3 @@ "main": "out/odata-to-abstract-sql.js", | ||
"dependencies": { | ||
"@balena/abstract-sql-compiler": "^7.4.2", | ||
"@balena/abstract-sql-compiler": "^7.13.4", | ||
"@balena/odata-parser": "^2.2.1", | ||
@@ -54,7 +54,7 @@ "@types/lodash": "^4.14.165", | ||
"bail": true, | ||
"_": "test/resource_parsing.coffee" | ||
"_": "test/*.coffee" | ||
}, | ||
"versionist": { | ||
"publishedAt": "2021-07-28T12:31:10.760Z" | ||
"publishedAt": "2021-08-24T17:04:50.089Z" | ||
} | ||
} |
@@ -1083,16 +1083,20 @@ import * as _ from 'lodash'; | ||
} else { | ||
// Used as ReferencedProperty a DateValue has to be handled with a date_trunc | ||
// TODO: How to get the underlying db engine on this.layer | ||
// Natively created timestamps in postgres have a microseconds precision | ||
// js has only milliseconds precision, thus retrieved timestamps may fail on eq, ne, gt, lt comparisons | ||
// furthermore retrieved timestamps should be truncated on database and not on the db abstraction layer | ||
// thus SBVR Date Time fields have to be truncated to millisecond precision | ||
// getting schema dataType from field mapping | ||
let fieldDefinition; | ||
const mapping = this.ResourceMapping(prop.resource); | ||
if (mapping[prop.name]) { | ||
const fieldDefinition = _.find(prop.resource.fields, { | ||
fieldName: mapping[prop.name][1], | ||
}); | ||
if ( | ||
fieldDefinition?.dataType === 'Date Time' || | ||
fieldDefinition?.dataType === 'Date' | ||
) { | ||
fieldDefinition = prop.resource.fields.find( | ||
(f) => f.fieldName === mapping[prop.name][1], | ||
); | ||
// when date time field from schema => hardcoded DateTrunc | ||
// following abstractsql to sql compiler have to check engine to translate to proper eninge based sql query | ||
if (fieldDefinition?.dataType === 'Date Time') { | ||
return [ | ||
'DateTrunc', | ||
['Text', 'milliseconds'], | ||
['EmbeddedText', 'milliseconds'], | ||
this.ReferencedField(prop.resource, prop.name), | ||
@@ -1102,2 +1106,3 @@ ]; | ||
} | ||
return this.ReferencedField(prop.resource, prop.name); | ||
@@ -1104,0 +1109,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
399030
2987