mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-24 01:06:07 +08:00
32 lines
699 B
JavaScript
32 lines
699 B
JavaScript
const Sequelize = require('sequelize');
|
|
|
|
module.exports = {
|
|
typeJSON: function typeJSON(key) {
|
|
return {
|
|
type: Sequelize.STRING,
|
|
get: function get() {
|
|
const val = this.getDataValue(key);
|
|
if (typeof val === 'string') {
|
|
try {
|
|
return JSON.parse(val)
|
|
} catch (e) {
|
|
return val
|
|
}
|
|
}
|
|
return val
|
|
},
|
|
set: function set(val) {
|
|
let valToSet = val
|
|
if (typeof val !== 'string') {
|
|
try {
|
|
valToSet = JSON.stringify(val)
|
|
} catch (e) {
|
|
valToSet = val;
|
|
}
|
|
}
|
|
return this.setDataValue(key, valToSet)
|
|
},
|
|
}
|
|
},
|
|
}
|