Files
nepiedg 1ad775be63 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.
2026-01-03 02:35:11 +00:00

31 lines
1.0 KiB
Go
Executable File

package model
import (
"time"
"gorm.io/gorm"
)
type Product struct {
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;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 "商品"
}