You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

84 lines
2.1 KiB

import { Sequelize, DataTypes, Optional, Model } from "sequelize"
interface ColorAttributes {
id: number
/**
* 颜色名
*/
name: string
/**
* 颜色值
*/
value: string
/**
* 颜色描述
*/
desctibe: string
/**
* 示例链接
*/
example_link: string
createdAt?: Date
updatedAt?: Date
deletedAt?: Date
}
export interface ColorInput extends Optional<ColorAttributes, "id"> {}
export interface ColorOutput extends Required<ColorAttributes> {}
export type TColorModel = ReturnType<typeof ColorModel>
type DT = typeof DataTypes
export default function ColorModel(sequelize: Sequelize, DataTypes: DT) {
class Color extends Model<ColorAttributes, ColorInput> implements ColorAttributes {
public id!: number
public name!: string
public value!: string
public desctibe: string
public example_link: string
// timestamps!
public readonly createdAt!: Date
public readonly updatedAt!: Date
public readonly deletedAt!: Date
}
Color.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
value: {
type: DataTypes.STRING,
allowNull: false,
},
desctibe: {
type: DataTypes.STRING,
},
example_link: {
type: DataTypes.STRING,
},
},
{
modelName: "color",
sequelize,
underscored: true,
deletedAt: true,
timestamps: true,
paranoid: true, // 对模型施加了一个软删除
},
)
// 覆盖Color的toJSON方法
Color.prototype.toJSON = function () {
const values = Object.assign({}, this.get()) as ColorAttributes
delete values.deletedAt
return values
}
Color.associate = function (models) {}
return Color
}