YiTao/model/model.go

31 lines
521 B
Go
Raw Normal View History

2024-11-09 14:59:27 +08:00
package model
import (
"time"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var DB *gorm.DB
type BaseModel struct {
ID uint `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
}
func ConnectToDb(dsn string) *gorm.DB {
var err error
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic(err)
}
2024-11-09 22:11:24 +08:00
err = DB.AutoMigrate(&CaptchaModel{}, &UserModel{}, &ItemModel{}, &LoginLogModel{}, &FileModel{}, &TypeModel{})
2024-11-09 14:59:27 +08:00
return DB
}
type ModelInterface interface {
TableName() string
}