package model import ( "time" "gorm.io/gorm" ) const ( DefaultWordBookID = "00000000000000000000000000000001" DefaultWordBookCode = "default" ) type WordBook struct { ID string `json:"id" gorm:"primaryKey;size:32"` Code string `json:"code" gorm:"size:64;uniqueIndex;not null"` Name string `json:"name" gorm:"size:120;not null"` SourceBookID string `json:"source_book_id" gorm:"size:64;uniqueIndex"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (WordBook) TableName() string { return "word_books" } func (b *WordBook) BeforeCreate(tx *gorm.DB) error { if b.ID == "" { b.ID = NewID() } return nil }