Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/db/gorm.go

44 lignes
982 o
Go
Brut Vue normale Historique

package db
import (
2017-05-10 19:29:35 +02:00
"github.com/azhao12345/gorm"
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/model"
2017-05-06 20:27:26 +02:00
"github.com/ewhal/nyaa/util/log"
2017-05-06 17:07:50 +02:00
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
2017-05-06 20:27:26 +02:00
var ORM *gorm.DB
var IsSqlite bool
// GormInit init gorm ORM.
2017-05-06 20:27:26 +02:00
func GormInit(conf *config.Config) (*gorm.DB, error) {
db, openErr := gorm.Open(conf.DBType, conf.DBParams)
if openErr != nil {
log.CheckError(openErr)
return nil, openErr
}
IsSqlite = conf.DBType == "sqlite"
connectionErr := db.DB().Ping()
if connectionErr != nil {
log.CheckError(connectionErr)
return nil, connectionErr
}
db.DB().SetMaxIdleConns(10)
db.DB().SetMaxOpenConns(100)
if config.Environment == "DEVELOPMENT" {
db.LogMode(true)
}
2017-05-10 19:29:35 +02:00
db.AutoMigrate(&model.User{}, &model.UserFollows{}, &model.UserUploadsOld{})
db.AutoMigrate(&model.Torrent{}, &model.TorrentReport{})
db.AutoMigrate(&model.Comment{}, &model.OldComment{})
return db, nil
}