starrocks_officail.go
1.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
}