starrocks_officail.go 816 字节
package starrocks

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
	"time"
)

var DBOfficial *sql.DB

func InitDBOfficial() error {
	var err error
	DBOfficial, err = sql.Open("mysql", constant.STARROCKS_MYSQL_DATA_SOURCE)
	if err != nil {
		return err
	}
	// See "Important settings" section.
	DBOfficial.SetConnMaxLifetime(time.Minute * 3)
	DBOfficial.SetMaxOpenConns(2)
	DBOfficial.SetMaxIdleConns(2)
	return nil
}

func ExecOfficial(sql string) error {
	log.Logger.Debug(sql)
	result, err := DBOfficial.Exec(sql)
	if err != nil {
		return err
	}
	_, err = result.RowsAffected()
	if err != nil {
		return err
	}
	return nil
}