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

Commit 2ab9439d by Jan Aagaard Meier

bug(datatypes) Fix datatypes parsing for mariadb and mssql

1 parent 9b61b5a2
...@@ -48,7 +48,12 @@ ConnectionManager = function(dialect, sequelize) { ...@@ -48,7 +48,12 @@ ConnectionManager = function(dialect, sequelize) {
ConnectionManager.prototype.refreshTypeParser = function(dataTypes) { ConnectionManager.prototype.refreshTypeParser = function(dataTypes) {
_.each(dataTypes, function (dataType, key) { _.each(dataTypes, function (dataType, key) {
if (dataType.hasOwnProperty('parse')) { if (dataType.hasOwnProperty('parse')) {
if (dataType.types[this.dialectName]) { var dialectName = this.dialectName;
if (dialectName === 'mariadb') {
dialectName = 'mysql';
}
if (dataType.types[dialectName]) {
this.$refreshTypeParser(dataType); this.$refreshTypeParser(dataType);
} else { } else {
throw new Error('Parse function not supported for type ' + dataType.key + ' in dialect ' + this.dialectName); throw new Error('Parse function not supported for type ' + dataType.key + ' in dialect ' + this.dialectName);
......
...@@ -78,7 +78,7 @@ Query.prototype.run = function(sql, parameters) { ...@@ -78,7 +78,7 @@ Query.prototype.run = function(sql, parameters) {
, value = column.value , value = column.value
, parse = parserStore.get(typeid); , parse = parserStore.get(typeid);
if (value !== null & parse) { if (value !== null & !!parse) {
value = parse(value); value = parse(value);
} }
row[column.metadata.colName] = value; row[column.metadata.colName] = value;
......
...@@ -10,7 +10,7 @@ module.exports = function (dialect) { ...@@ -10,7 +10,7 @@ module.exports = function (dialect) {
}, },
refresh: function (dataType) { refresh: function (dataType) {
dataType.types[dialect].forEach(function (type) { dataType.types[dialect].forEach(function (type) {
stores[dialect][type] = dataType.parse; stores[dialect][type] = dataType.parse;
}); });
}, },
get: function (type) { get: function (type) {
......
...@@ -35,7 +35,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -35,7 +35,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
types.setTypeParser(oid, 'text', converter); types.setTypeParser(oid, 'text', converter);
}); });
this.sequelize.connectionManager.refreshTypes(DataTypes.postgres); // Reload custom parsers for hstore and geometry this.sequelize.connectionManager.refreshTypeParser(DataTypes.postgres); // Reload custom parsers for hstore and geometry
break; break;
default: default:
this.sequelize.connectionManager.$clearTypeParser(); this.sequelize.connectionManager.$clearTypeParser();
...@@ -248,7 +248,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -248,7 +248,7 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
it('calls parse and stringify for GEOMETRY', function () { it('calls parse and stringify for GEOMETRY', function () {
var Type = new Sequelize.GEOMETRY(); var Type = new Sequelize.GEOMETRY();
if (['postgres', 'mysql'].indexOf(dialect) !== -1) { if (['postgres', 'mysql', 'mariadb'].indexOf(dialect) !== -1) {
return testSuccess(Type, { type: "Point", coordinates: [125.6, 10.1] }); return testSuccess(Type, { type: "Point", coordinates: [125.6, 10.1] });
} else { } else {
// Not implemented yet // Not implemented yet
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!