Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/modelGenerators/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ module.exports = class {
}
}
}
if (attribute._type === 'object') {
this[attributeName] = {
type: DataTypes.STRING,
allowNull: true,
get: function () {
const data = this.getDataValue(attributeName)
return data ? JSON.parse(data) : {}
},
set: function (val) {
this.setDataValue(attributeName, JSON.stringify(val))
}
}
}
if (attribute._flags) {
if (attribute._flags.presence === 'required') {
this[attributeName].allowNull = false
Expand Down
18 changes: 18 additions & 0 deletions lib/modelGenerators/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ module.exports = class extends Default {
allowNull: true
}
break
case 'object':
this[attributeName] = {
type: DataTypes.ARRAY(DataTypes.JSONB),
allowNull: true
}
}
this[attributeName].get = function () {
return this.getDataValue(attributeName) || []
Expand All @@ -60,6 +65,19 @@ module.exports = class extends Default {
this.setDataValue(attributeName, val || [])
}
}
if (attribute._type === 'object') {
// PostgreSQL has JSONB support, so lets use that
this[attributeName] = {
type: DataTypes.JSONB,
allowNull: true
}
this[attributeName].get = function () {
return this.getDataValue(attributeName) || {}
}
this[attributeName].set = function (val) {
this.setDataValue(attributeName, val || {})
}
}
}
}
}