Enhance database models with comments and table descriptions
- Added comments to various fields in the database models for better clarity and understanding. - Implemented TableComment methods for several models to provide descriptive information about their purpose. - Updated the AutoMigrate function to support setting table comments in the database. - Improved overall documentation within the code to facilitate future maintenance and development.
This commit is contained in:
+15
-11
@@ -7,20 +7,24 @@ import (
|
||||
)
|
||||
|
||||
type Product struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
ID uint `gorm:"primarykey;comment:商品ID" json:"id"`
|
||||
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||
|
||||
Name string `gorm:"size:200;not null" json:"name"`
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"`
|
||||
Stock int `gorm:"default:0" json:"stock"`
|
||||
ImageURL string `gorm:"size:500" json:"image_url"`
|
||||
Category string `gorm:"size:50" json:"category"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
Name string `gorm:"size:200;not null;comment:商品名" json:"name"`
|
||||
Description string `gorm:"type:text;comment:商品描述" json:"description"`
|
||||
Price float64 `gorm:"type:decimal(10,2);not null;comment:价格" json:"price"`
|
||||
Stock int `gorm:"default:0;comment:库存" json:"stock"`
|
||||
ImageURL string `gorm:"size:500;comment:图片URL" json:"image_url"`
|
||||
Category string `gorm:"size:50;comment:分类" json:"category"`
|
||||
Status int `gorm:"default:1;comment:状态(1上架/0下架)" json:"status"`
|
||||
}
|
||||
|
||||
func (Product) TableName() string {
|
||||
return "products"
|
||||
}
|
||||
|
||||
func (Product) TableComment() string {
|
||||
return "商品"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user