gophertype/pkg/models/models.go

27 lines
478 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
DB.AutoMigrate(&User{})
DB.Debug().AutoMigrate(&Post{})
2019-11-27 00:54:02 +00:00
DB.AutoMigrate(&TaggedPost{})
DB.AutoMigrate(&Comment{})
2019-11-15 03:03:56 +00:00
}