blob: b65c0141b39f3342678f295377d58f4ffc07e74b (
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(key: string, that: Model): any {
return JSON.parse(that.getDataValue(key));
}
export 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 (): string[] {
return jsonParseGet(key, this);
},
set: function (val: string[]) {
return jsonParseSet(key, this, val);
},
allowNull: false,
defaultValue: '[]'
};
}
|