Comparing version 6.11.1 to 6.11.2
@@ -5,2 +5,9 @@ # Changelog | ||
### [6.11.2](https://gitlab.com/dmfay/massive-js/compare/v6.11.1...v6.11.2) (2023-02-02) | ||
### Bug Fixes | ||
* cast date columns to ::date ([31cfff2](https://gitlab.com/dmfay/massive-js/commit/31cfff239ffde09059704bed5053167d48eb5663)) | ||
### [6.11.1](https://gitlab.com/dmfay/massive-js/compare/v6.11.0...v6.11.1) (2023-01-07) | ||
@@ -7,0 +14,0 @@ |
@@ -6,5 +6,7 @@ 'use strict'; | ||
exports = module.exports = function (db) { | ||
return db.instance.query(db.loader.queryFiles['tables.sql'], db.loader).then(tables => decompose({ | ||
const file = db.serverAtLeast('9.5') ? 'tables.sql' : 'tables-legacy.sql'; | ||
return db.instance.query(db.loader.queryFiles[file], db.loader).then(tables => decompose({ | ||
pk: ['schema', 'name'], | ||
columns: ['schema', 'name', 'parent', 'pk', 'columns', 'is_insertable_into'], | ||
columns: ['schema', 'name', 'parent', 'pk', 'columns', 'types', 'is_insertable_into'], | ||
fks: { | ||
@@ -11,0 +13,0 @@ pk: 'fk', |
@@ -41,2 +41,3 @@ 'use strict'; | ||
})); | ||
this.types = spec.types; | ||
this.isMatview = spec.is_matview || false; | ||
@@ -631,3 +632,4 @@ }; | ||
joinRelations: [], | ||
joinColumns: [] | ||
joinColumns: [], | ||
joinTypes: [] | ||
}); | ||
@@ -638,4 +640,4 @@ | ||
// Add the join relation and its columns to the node accumulator. It's | ||
// stored there because we want the column order and JOIN order to match | ||
// Add the join relation, its columns and types to the node accumulator. | ||
// It's stored there because we want the column order and JOIN order to match | ||
// the tree layout (a "pre-order" traversal: parents before children, in | ||
@@ -658,2 +660,3 @@ // sequence) -- Postgres won't toposort JOIN clauses for us. However, since | ||
}), acc[alias].joinColumns); | ||
acc.joinTypes = _.extend(acc.joinTypes, _.mapKeys(readable.types, (_v, k) => `${alias}.${k}`)); | ||
@@ -664,2 +667,3 @@ // strictly speaking, only leftover joinRelations or joinColumns on the | ||
delete acc[alias].joinColumns; | ||
delete acc[alias].joinTypes; | ||
@@ -675,3 +679,4 @@ return acc; | ||
return c; | ||
}) | ||
}), | ||
joinTypes: _.mapKeys(this.types, (_v, k) => `${this.name}.${k}`) | ||
}); | ||
@@ -685,5 +690,7 @@ | ||
const joinColumns = definition.joinColumns; | ||
const joinTypes = definition.joinTypes; | ||
delete definition.joinRelations; | ||
delete definition.joinColumns; | ||
delete definition.joinTypes; | ||
@@ -696,2 +703,3 @@ const clone = new Proxy(this, { | ||
case 'columns': return joinColumns; | ||
case 'types': return joinTypes; | ||
} | ||
@@ -698,0 +706,0 @@ |
@@ -7,5 +7,12 @@ 'use strict'; | ||
const castTimestamp = (value) => { | ||
const castTimestamp = (value, type) => { | ||
if (_.isDate(value)) { | ||
return '::timestamptz'; | ||
switch (type) { | ||
case 'date': | ||
return '::date'; | ||
case 'timestamp without time zone': | ||
return '::timestamp'; | ||
default: | ||
return '::timestamptz'; | ||
} | ||
} | ||
@@ -24,3 +31,3 @@ | ||
condition.params = condition.value; | ||
condition.value = `$${condition.offset}${castTimestamp(condition.value[0])} AND $${condition.offset + 1}${castTimestamp(condition.value[1])}`; | ||
condition.value = `$${condition.offset}${castTimestamp(condition.value[0], condition.type)} AND $${condition.offset + 1}${castTimestamp(condition.value[1], condition.type)}`; | ||
condition.offset += 2; | ||
@@ -47,3 +54,3 @@ | ||
condition.params = condition.params.concat(condition.value); | ||
const inList = condition.value.map((v, index) => [`$${condition.offset + index}${castTimestamp(v)}`]); | ||
const inList = condition.value.map((v, index) => [`$${condition.offset + index}${castTimestamp(v, condition.type)}`]); | ||
condition.offset += condition.value.length; | ||
@@ -87,3 +94,3 @@ condition.value = `(${inList.join(',')})`; | ||
condition.value = `$${condition.offset}${castTimestamp(condition.value)}`; | ||
condition.value = `$${condition.offset}${castTimestamp(condition.value, condition.type)}`; | ||
@@ -116,3 +123,3 @@ return condition; | ||
condition.value = `$${condition.offset}${castTimestamp(condition.value)}`; | ||
condition.value = `$${condition.offset}${castTimestamp(condition.value, condition.type)}`; | ||
@@ -119,0 +126,0 @@ return condition; |
@@ -224,6 +224,12 @@ 'use strict'; | ||
const resolvedRelation = relation || alias || (source ? source.name : undefined); | ||
return { | ||
schema, | ||
relation: relation || alias || (source ? source.name : undefined), | ||
relation: resolvedRelation, | ||
field, | ||
type: source && source.types | ||
// Try both "relation.field" and "field" as joins prefix types with the table alias | ||
? source.types[`${resolvedRelation}.${field}`] || source.types[field] | ||
: undefined, | ||
pathElements, | ||
@@ -230,0 +236,0 @@ path, |
{ | ||
"name": "massive", | ||
"version": "6.11.1", | ||
"version": "6.11.2", | ||
"description": "A small query tool for Postgres that embraces json and makes life simpler", | ||
@@ -5,0 +5,0 @@ "homepage": "https://massivejs.org", |
Sorry, the diff of this file is not supported yet
3123
196448