2019-11-15 03:03:56 +00:00
|
|
|
package models
|
|
|
|
|
2020-02-18 02:10:35 +00:00
|
|
|
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
|
|
|
|
|
2020-02-18 02:10:35 +00:00
|
|
|
// 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
|
|
|
}
|