add model

This commit is contained in:
2026-01-14 12:49:17 +08:00
parent 845aef2fe8
commit db1d5397c0
2 changed files with 94 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package models
import (
"time"
"gorm.io/gorm"
)
// LastDaily 股票日线数据
type LastDaily struct {
ID uint `gorm:"primarykey;autoIncrement" json:"id"`
TsCode string `gorm:"type:varchar(20);not null;index:idx_ts_code;comment:股票代码" json:"ts_code"`
TradeDate time.Time `gorm:"type:date;not null;index:idx_trade_date;comment:交易日期" json:"trade_date"`
Open float64 `gorm:"type:decimal(10,4);comment:开盘价" json:"open"`
High float64 `gorm:"type:decimal(10,4);comment:最高价" json:"high"`
Low float64 `gorm:"type:decimal(10,4);comment:最低价" json:"low"`
Close float64 `gorm:"type:decimal(10,4);comment:收盘价" json:"close"`
PreClose float64 `gorm:"type:decimal(10,4);comment:昨收价(除权价)" json:"pre_close"`
Change float64 `gorm:"type:decimal(10,4);comment:涨跌额" json:"change"`
PctChg float64 `gorm:"type:decimal(10,6);comment:涨跌幅(%)" json:"pct_chg"`
Vol float64 `gorm:"type:decimal(15,2);comment:成交量(手)" json:"vol"`
Amount float64 `gorm:"type:decimal(20,2);comment:成交额(千元)" json:"amount"`
}
func init() {
database.AppendMigrate(&LastDaily{})
}
// TableName 指定表名
func (LastDaily) TableName() string {
return "last_daily"
}
// Indexes 定义复合索引可选也可以在migration中创建
func (LastDaily) Indexes() []gorm.Index {
return []gorm.Index{
&gorm.IndexModel{
Name: "idx_ts_code_trade_date",
Fields: []string{"ts_code", "trade_date"},
},
}
}