blob: 243b2743b35c5a625bb02af52463fca46b52a117 (
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';
export function jsonParseGet(this: Model, key: string): any {
return JSON.parse(this.getDataValue(key));
}
export function jsonParseSet(this: Model, key: string, value: any): any {
return this.setDataValue(key, JSON.stringify(value));
}
export function jsonArrayInit(key: string): any {
return {
type: DataTypes.TEXT,
get: function (): string[] {
return jsonParseGet.call(this, key);
},
set: function (val: string[]) {
return jsonParseSet.call(this, key, val);
},
allowNull: false,
defaultValue: '[]'
};
}
|