100ecffda7
* fix scraper, optimize updates so it doesn't suck massive ass * fucking ass
43 lignes
982 o
Go
43 lignes
982 o
Go
package db
|
|
|
|
import (
|
|
"github.com/azhao12345/gorm"
|
|
"github.com/ewhal/nyaa/config"
|
|
"github.com/ewhal/nyaa/model"
|
|
"github.com/ewhal/nyaa/util/log"
|
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
|
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
|
)
|
|
|
|
var ORM *gorm.DB
|
|
|
|
var IsSqlite bool
|
|
|
|
// GormInit init gorm ORM.
|
|
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)
|
|
}
|
|
|
|
db.AutoMigrate(&model.User{}, &model.UserFollows{}, &model.UserUploadsOld{})
|
|
db.AutoMigrate(&model.Torrent{}, &model.TorrentReport{})
|
|
db.AutoMigrate(&model.Comment{}, &model.OldComment{})
|
|
|
|
return db, nil
|
|
}
|