|
|
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
|
|
|
sql.Register("mysql-star", &mysql.MySQLDriver{})
|
|
|
DBOfficial, err = sql.Open("mysql-star", 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 {
|
|
|
log.Logger.Error("exec error", map[string]interface{}{"err": err.Error()})
|
|
|
return err
|
|
|
}
|
|
|
_, err = result.RowsAffected()
|
|
|
if err != nil {
|
|
|
log.Logger.Error("result error", map[string]interface{}{"result": err.Error()})
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|