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

38 lignes
933 o
Go
Brut Vue normale Historique

package db
import (
"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-10 10:17:21 +02:00
"github.com/azhao12345/gorm"
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
// 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
}
connectionErr := db.DB().Ping()
if connectionErr != nil {
log.CheckError(connectionErr)
return nil, connectionErr
}
db.DB().SetMaxIdleConns(10)
db.DB().SetMaxOpenConns(100)
// TODO: Enable Gorm initialization for non-development builds
if config.Environment == "DEVELOPMENT" {
db.LogMode(true)
2017-05-10 06:20:45 +02:00
db.AutoMigrate(&model.Torrent{}, &model.UserFollows{}, &model.User{}, &model.Comment{}, &model.OldComment{}, &model.TorrentReport{})
}
return db, nil
}