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

Support PostgreSQL JSON datatype in models

1 parent 572adf67
Showing with 13 additions and 0 deletions
...@@ -404,6 +404,11 @@ module.exports = { ...@@ -404,6 +404,11 @@ module.exports = {
HSTORE: 'HSTORE', HSTORE: 'HSTORE',
/** /**
* A JSON string column. Only available in postgres.
*/
JSON: 'JSON',
/**
* A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model * A virtual value that is not stored in the DB. This could for example be useful if you want to provide a default value in your model
* that is returned to the user but not stored in the DB. * that is returned to the user but not stored in the DB.
* *
......
...@@ -248,6 +248,7 @@ module.exports = (function() { ...@@ -248,6 +248,7 @@ module.exports = (function() {
this._booleanAttributes = []; this._booleanAttributes = [];
this._dateAttributes = []; this._dateAttributes = [];
this._hstoreAttributes = []; this._hstoreAttributes = [];
this._jsonAttributes = [];
this._virtualAttributes = []; this._virtualAttributes = [];
this._defaultValues = {}; this._defaultValues = {};
this.Instance.prototype.validators = {}; this.Instance.prototype.validators = {};
...@@ -261,6 +262,8 @@ module.exports = (function() { ...@@ -261,6 +262,8 @@ module.exports = (function() {
self._dateAttributes.push(name); self._dateAttributes.push(name);
} else if (type === DataTypes.HSTORE) { } else if (type === DataTypes.HSTORE) {
self._hstoreAttributes.push(name); self._hstoreAttributes.push(name);
} else if (type === DataTypes.JSON) {
self._jsonAttributes.push(name);
} else if (type === DataTypes.VIRTUAL) { } else if (type === DataTypes.VIRTUAL) {
self._virtualAttributes.push(name); self._virtualAttributes.push(name);
} }
...@@ -290,6 +293,11 @@ module.exports = (function() { ...@@ -290,6 +293,11 @@ module.exports = (function() {
return self._hstoreAttributes.indexOf(key) !== -1; return self._hstoreAttributes.indexOf(key) !== -1;
}); });
this._hasJsonAttributes = !!this._jsonAttributes.length;
this._isJsonAttribute = Utils._.memoize(function(key) {
return self._jsonAttributes.indexOf(key) !== -1;
});
this._hasVirtualAttributes = !!this._virtualAttributes.length; this._hasVirtualAttributes = !!this._virtualAttributes.length;
this._isVirtualAttribute = Utils._.memoize(function(key) { this._isVirtualAttribute = Utils._.memoize(function(key) {
return self._virtualAttributes.indexOf(key) !== -1; return self._virtualAttributes.indexOf(key) !== -1;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!