import { Sequelize, DataTypes, Optional, Model } from "sequelize" interface UserInfoAttributes { id: number user_id: number nickname: string email: string avatar: string tel: string createdAt?: Date updatedAt?: Date deletedAt?: Date } export interface UserInfoInput extends Optional {} export interface UserInfoOuput extends Required {} export type TUserInfoModel = ReturnType type DT = typeof DataTypes export default function UserInfoModel(sequelize: Sequelize, DataTypes: DT) { class UserInfo extends Model implements UserInfoAttributes { public id: number public user_id: number public nickname: string public email: string public avatar: string public tel: string // timestamps! public readonly createdAt!: Date public readonly updatedAt!: Date public readonly deletedAt!: Date } UserInfo.init( { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, user_id: { type: DataTypes.INTEGER, allowNull: false, }, nickname: { type: DataTypes.STRING, allowNull: false, }, email: { type: DataTypes.STRING, }, avatar: { type: DataTypes.STRING, }, tel: { type: DataTypes.STRING, }, }, { modelName: "UserInfo", sequelize, timestamps: true, paranoid: true, // 对模型施加了一个软删除 }, ) // 覆盖User的toJSON方法 interface UserInfo { toJSON: () => UserInfoOuput } UserInfo.associate = function (models) { models["UserInfo"].belongsTo(models["User"], { foreignKey: "user_id" }) } return UserInfo }