gophertype/pkg/models/models.go

24 lines
435 B
Go
Raw Normal View History

2019-11-15 03:03:56 +00:00
package models
import (
"time"
"github.com/jinzhu/gorm"
)
2019-11-15 03:03:56 +00:00
// DB is the database handle for all the models.
var DB *gorm.DB
// BaseModel is the base column set for all models.
type BaseModel struct {
ID int `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
}
2019-11-15 03:03:56 +00:00
// UseDB registers a database driver.
func UseDB(db *gorm.DB) {
DB = db
2020-02-18 03:40:57 +00:00
DB.AutoMigrate(&User{}, &Post{}, &TaggedPost{}, &Comment{}, &Question{})
2019-11-15 03:03:56 +00:00
}