blob: f558ecbd99b48d491f781adcc93a906e058c75c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import { DataTypes, Model } from 'sequelize';
export const NEVER_USED = 'This should never be executed';
function jsonParseGet(key: string, that: Model): any {
return JSON.parse(that.getDataValue(key));
}
function jsonParseSet(key: string, that: Model, value: any): any {
return that.setDataValue(key, JSON.stringify(value));
}
export function jsonArrayInit(key: string): any {
return {
type: DataTypes.TEXT,
get: function () {
return jsonParseGet(key, this);
},
set: function (val: string[]) {
return jsonParseSet(key, this, val);
},
allowNull: false,
defaultValue: '[]'
};
}
|