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

Commit a4d56f30 by Jan Aagaard Meier

bug(datatypes) Lazy-load pg-hstore to prevent error about missing pg-hstore in o…

…ther dialects. Thanks to breakingthings
1 parent 6e13324f
...@@ -7,8 +7,7 @@ var util = require('util') ...@@ -7,8 +7,7 @@ var util = require('util')
, sequelizeErrors = require('./errors') , sequelizeErrors = require('./errors')
, warnings = {} , warnings = {}
, Validator = require('validator') , Validator = require('validator')
, moment = require('moment-timezone') , moment = require('moment-timezone');
, hstore = require('./dialects/postgres/hstore');
/** /**
* A convenience class holding commonly used data types. The datatypes are used when defining a new model using `Sequelize.define`, like this: * A convenience class holding commonly used data types. The datatypes are used when defining a new model using `Sequelize.define`, like this:
...@@ -478,11 +477,6 @@ HSTORE.prototype.validate = function(value) { ...@@ -478,11 +477,6 @@ HSTORE.prototype.validate = function(value) {
return true; return true;
}; };
HSTORE.prototype.escape = false;
HSTORE.prototype.$stringify = function (value) {
return '\'' + hstore.stringify(value) + '\'';
};
/** /**
* A JSON string column. Only available in postgres. * A JSON string column. Only available in postgres.
* @property JSON * @property JSON
......
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
/*jshint -W110 */ /*jshint -W110 */
var _ = require('lodash') var _ = require('lodash')
, wkx = require('wkx') , wkx = require('wkx');
, hstore = require('./hstore');
module.exports = function (BaseTypes) { module.exports = function (BaseTypes) {
var warn = BaseTypes.ABSTRACT.warn.bind(undefined, 'http://www.postgresql.org/docs/9.4/static/datatype.html'); var warn = BaseTypes.ABSTRACT.warn.bind(undefined, 'http://www.postgresql.org/docs/9.4/static/datatype.html');
...@@ -270,12 +269,26 @@ module.exports = function (BaseTypes) { ...@@ -270,12 +269,26 @@ module.exports = function (BaseTypes) {
return 'ST_GeomFromGeoJSON(\'' + JSON.stringify(value) + '\')'; return 'ST_GeomFromGeoJSON(\'' + JSON.stringify(value) + '\')';
}; };
var HSTORE = BaseTypes.HSTORE.inherits(); var hstore;
var HSTORE = BaseTypes.HSTORE.inherits(function () {
if (!(this instanceof HSTORE)) return new HSTORE();
BaseTypes.HSTORE.apply(this, arguments);
if (!hstore) {
// All datatype files are loaded at import - make sure we don't load the hstore parser before a hstore is instantiated
hstore = require('./hstore');
}
});
HSTORE.parse = function (value) { HSTORE.parse = function (value) {
return hstore.parse(value); return hstore.parse(value);
}; };
HSTORE.prototype.escape = false;
HSTORE.prototype.$stringify = function (value) {
return "'" + hstore.stringify(value) + "'";
};
BaseTypes.HSTORE.types.postgres = { BaseTypes.HSTORE.types.postgres = {
oids: [], oids: [],
array_oids: [] array_oids: []
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!