Skip to content

Commit cec3aed

Browse files
committed
SQL Client struct modify
1 parent 66c4834 commit cec3aed

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pkg/common/utils/mysql/doris.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
package mysql
1919

2020
import (
21-
_ "github.com/go-sql-driver/mysql"
22-
"k8s.io/klog/v2"
2321
"sort"
2422
"strconv"
2523
"strings"
24+
25+
_ "github.com/go-sql-driver/mysql"
26+
"k8s.io/klog/v2"
2627
)
2728

2829
const (
@@ -67,7 +68,6 @@ type Backend struct {
6768
TabletNum int64 `json:"tablet_num" db:"TabletNum"`
6869
DataUsedCapacity string `json:"data_used_capacity" db:"DataUsedCapacity"`
6970
TrashUsedCapacity string `json:"trash_used_capacity" db:"TrashUsedCapacity"`
70-
TrashUsedCapcacity string `json:"trash_used_capcacity" db:"TrashUsedCapcacity"`
7171
AvailCapacity string `json:"avail_capacity" db:"AvailCapacity"`
7272
TotalCapacity string `json:"total_capacity" db:"TotalCapacity"`
7373
UsedPct string `json:"used_pct" db:"UsedPct"`

pkg/common/utils/mysql/mysql.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ type DB struct {
6060
*sqlx.DB
6161
}
6262

63+
// Debugging this code cannot be done through a standalone process on the host machine;
64+
// it can only be done by building the operator because it depends on the network configuration of the Kubernetes cluster.
65+
6366
func NewDorisSqlDB(cfg DBConfig, tlsConfig *TLSConfig, secret *corev1.Secret) (*DB, error) {
6467
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Database)
6568
rootCertPool := x509.NewCertPool()
@@ -140,22 +143,26 @@ func (db *DB) Close() error {
140143
}
141144

142145
func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error) {
143-
return db.DB.Exec(query, args...)
146+
return db.DB.Unsafe().Exec(query, args...)
144147
}
145148

146149
func (db *DB) Select(dest interface{}, query string, args ...interface{}) error {
147150
return db.DB.Select(dest, query, args...)
148151
}
149152

153+
func (db *DB) USelect(dest interface{}, query string, args ...interface{}) error {
154+
return db.DB.Unsafe().Select(dest, query, args...)
155+
}
156+
150157
func (db *DB) ShowFrontends() ([]*Frontend, error) {
151158
var fes []*Frontend
152-
err := db.Unsafe().Select(&fes, "show frontends")
159+
err := db.USelect(&fes, "show frontends")
153160
return fes, err
154161
}
155162

156163
func (db *DB) ShowBackends() ([]*Backend, error) {
157164
var bes []*Backend
158-
err := db.Unsafe().Select(&bes, "show backends")
165+
err := db.USelect(&bes, "show backends")
159166
return bes, err
160167
}
161168

0 commit comments

Comments
 (0)