Trying to type a model. How can I use JSONB sequelize postgres type?
Keep in mind sequelize-typescript does not provide typings for sequelize - these are seperate things. A lot of the types in sequelize-typescript augment, refer to, or extend what sequelize already has.
`@Table({ modelName: "Userprefs", tableName: "userprefs" })
export default class UserPrefs extends Model
@PrimaryKey
@Column({ field: "id", autoIncrement: true })
id!: number;
@Column({ field: "docid" })
docId!: string;
@CreatedAt
@Column({ field: "created_on" })
createdOn!: Date;
@Column({ field: "prefs" })
prefs!: DataTypes.JSONB;
}`
It doesn't like how I'm referring to JSONB. Can anyone help?
@Column(DataType.JSONB)
prefs!: object;
Naturally, prefs might want to follow a certain structure rather than an arbitrary object (meaning, use a more specific type).
You may also be interested in the underscored option for @Table.
@oldmud0 I am definitely interested in the underscored option. Where can I find more info?
See http://docs.sequelizejs.com/manual/models-definition.html#configuration:
// Will automatically set field option for all attributes to snake cased name.
// Does not override attribute with field option already defined
underscored: true,
Closing this since it's solved
Thanks!
Most helpful comment
Naturally,
prefsmight want to follow a certain structure rather than an arbitrary object (meaning, use a more specific type).You may also be interested in the
underscoredoption for@Table.