From 96e1a96f2e4b2cc60610104da256eccff6828371 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 20 Aug 2025 20:59:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/dbm.go | 6 +++--- handler/dbm.go | 1 + service/dbmService.go | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dao/dbm.go b/dao/dbm.go index 5a44ef7..6ba4102 100644 --- a/dao/dbm.go +++ b/dao/dbm.go @@ -33,7 +33,7 @@ func CreateDBRunHistory(history *proto.SQLRunHistory) (uint, error) { return history.ID, nil } -func RunSQL(sql string, db_ *gorm.DB) (res map[string]interface{}, err error) { +func RunSQL(sql string, db_ *gorm.DB) (res []map[string]interface{}, err error) { var db2 *gorm.DB if proto.Config.SERVER_SQL_LOG { db2 = db_.Debug() @@ -67,7 +67,7 @@ func FindDBManageByAuthID(auth_id uint) ([]proto.DBManage, error) { } else { db2 = DB } - res := db2.Where("auth_id = ?", auth_id).Find(&db_infos) + res := db2.Where("user_id = ?", auth_id).Find(&db_infos) if res.Error != nil { return nil, res.Error } @@ -134,7 +134,7 @@ func FindDBRunHistoryByAuthID(auth_id int) ([]proto.SQLRunHistory, error) { } else { db2 = DB } - res := db2.Where("auth_id = ?", auth_id).Find(&histories) + res := db2.Where("user_id = ?", auth_id).Find(&histories) if res.Error != nil { return nil, res.Error } diff --git a/handler/dbm.go b/handler/dbm.go index 59307aa..edac578 100644 --- a/handler/dbm.go +++ b/handler/dbm.go @@ -36,6 +36,7 @@ func UpdateDBManageHandler(c *gin.Context) { resp.Data = dbManage } } + c.JSON(http.StatusOK, resp) } func GetSQLRunHistoryHandler(c *gin.Context) { diff --git a/service/dbmService.go b/service/dbmService.go index a008edc..7615af5 100644 --- a/service/dbmService.go +++ b/service/dbmService.go @@ -5,11 +5,12 @@ import ( "gorm.io/driver/mysql" "gorm.io/driver/postgres" "gorm.io/gorm" + "strconv" "videoplayer/dao" "videoplayer/proto" ) -func RunSQL(req *proto.RunSQLRequest) (map[string]interface{}, error) { +func RunSQL(req *proto.RunSQLRequest) ([]map[string]interface{}, error) { dbmInfo, err := dao.FindDBManageByID(req.DB_ID) if err != nil { @@ -38,13 +39,13 @@ func RunSQL(req *proto.RunSQLRequest) (map[string]interface{}, error) { func GetGORMDBObject(dbmInfo *proto.DBManage) (db_ *gorm.DB, err error) { switch dbmInfo.DB_Type { case proto.DB_TYPE_MYSQL: // MySQL - dsn := dbmInfo.DB_User + ":" + dbmInfo.DB_Password + "@tcp(" + dbmInfo.DB_IP + ":" + string(rune(dbmInfo.DB_Port)) + ")/" + dbmInfo.DB_NAME + "?charset=utf8mb4&parseTime=True&loc=Local" + dsn := dbmInfo.DB_User + ":" + dbmInfo.DB_Password + "@tcp(" + dbmInfo.DB_IP + ":" + strconv.Itoa(int(dbmInfo.DB_Port)) + ")/" + dbmInfo.DB_NAME + "?charset=utf8mb4&parseTime=True&loc=Local" db_, err = gorm.Open(mysql.Open(dsn), &gorm.Config{}) if err != nil { return nil, err } case proto.DB_TYPE_POSTGRES: // PostgreSQL - dsn := "host=" + dbmInfo.DB_IP + " user=" + dbmInfo.DB_User + " password=" + dbmInfo.DB_Password + " dbname=" + dbmInfo.DB_NAME + " port=" + string(rune(dbmInfo.DB_Port)) + " sslmode=disable TimeZone=Asia/Shanghai" + dsn := "host=" + dbmInfo.DB_IP + " user=" + dbmInfo.DB_User + " password=" + dbmInfo.DB_Password + " dbname=" + dbmInfo.DB_NAME + " port=" + strconv.Itoa(int(dbmInfo.DB_Port)) + " sslmode=disable TimeZone=Asia/Shanghai" db_, err = gorm.Open(postgres.Open(dsn), &gorm.Config{}) if err != nil { return nil, err @@ -52,7 +53,6 @@ func GetGORMDBObject(dbmInfo *proto.DBManage) (db_ *gorm.DB, err error) { default: err = errors.New("unsupported database type") } - return db_, err }