package initialize import ( "confrontation-training/global" "fmt" log "github.com/sirupsen/logrus" "gorm.io/driver/sqlite" "gorm.io/gorm" "gorm.io/gorm/schema" "time" ) func SQLite() { sqliteConfig := global.Config.SQLite db, err := gorm.Open(sqlite.Open(sqliteConfig.Url), &gorm.Config{ NamingStrategy: schema.NamingStrategy{ TablePrefix: "ct_", SingularTable: false, }, }) if err != nil { fmt.Printf("mysql error :%s", err.Error()) log.Infof("mysql error :%s", err.Error()) return } sqlDb, err := db.DB() if err != nil { fmt.Printf("mysql error :%s", err.Error()) log.Infof("mysql error :%s", err.Error()) } sqlDb.SetMaxIdleConns(10) sqlDb.SetMaxOpenConns(100) sqlDb.SetConnMaxLifetime(time.Hour) global.Db = db }