数据结构优化
This commit is contained in:
35
server/models/search_log.go
Normal file
35
server/models/search_log.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// SearchLog 搜索记录模型
|
||||
type SearchLog struct {
|
||||
ID uint `json:"id" gorm:"primaryKey;column:id"`
|
||||
Keyword string `json:"keyword" gorm:"column:keyword"`
|
||||
SearchType string `json:"searchType" gorm:"column:search_type"` // category/tag/column/keyword
|
||||
UserIP string `json:"userIp" gorm:"column:user_ip"`
|
||||
UserLocation string `json:"userLocation" gorm:"column:user_location"`
|
||||
DeletedAt int64 `json:"deletedAt" gorm:"column:deleted_at;default:0"`
|
||||
CreatedAt int64 `json:"createdAt" gorm:"column:created_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (SearchLog) TableName() string {
|
||||
return "search_logs"
|
||||
}
|
||||
|
||||
// BeforeCreate 创建前钩子
|
||||
func (sl *SearchLog) BeforeCreate(tx *gorm.DB) error {
|
||||
now := time.Now().Unix()
|
||||
if sl.CreatedAt == 0 {
|
||||
sl.CreatedAt = now
|
||||
}
|
||||
if sl.DeletedAt == 0 {
|
||||
sl.DeletedAt = 0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user