package dao

import (
	"fmt"
	"gorm.io/driver/mysql"

	"gorm.io/gorm"
	"youngee_b_api/model/system_model"
)

var (
	Db  *gorm.DB
	err error
)

func Init(config *system_model.Mysql) {
	dsn := "%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True&loc=Local"
	dsn = fmt.Sprintf(dsn, config.User, config.Password, config.Host, config.Port, config.Database)
	Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	if Db.Error != nil {
		panic(err)
	}

	//Db.DB().SetMaxIdleConns(10)
	//Db.DB().SetMaxOpenConns(100)
	//Db.DB().SetConnMaxLifetime(time.Hour)
}
