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

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')
, sequelizeErrors = require('./errors')
, warnings = {}
, Validator = require('validator')
, moment = require('moment-timezone')
, hstore = require('./dialects/postgres/hstore');
, moment = require('moment-timezone');
/**
* 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) {
return true;
};
HSTORE.prototype.escape = false;
HSTORE.prototype.$stringify = function (value) {
return '\'' + hstore.stringify(value) + '\'';
};
/**
* A JSON string column. Only available in postgres.
* @property JSON
......
......@@ -3,8 +3,7 @@
/*jshint -W110 */
var _ = require('lodash')
, wkx = require('wkx')
, hstore = require('./hstore');
, wkx = require('wkx');
module.exports = function (BaseTypes) {
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) {
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) {
return hstore.parse(value);
};
HSTORE.prototype.escape = false;
HSTORE.prototype.$stringify = function (value) {
return "'" + hstore.stringify(value) + "'";
};
BaseTypes.HSTORE.types.postgres = {
oids: [],
array_oids: []
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!