Merge branch 'refs/heads/feat-db-manager' into release
This commit is contained in:
commit
27c5b3cd3c
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"videoplayer/proto"
|
||||
|
|
@ -21,6 +22,9 @@ func Init() error {
|
|||
} else if proto.Config.DB == 1 {
|
||||
dsn = proto.Config.PG_DSN
|
||||
db, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
} else if proto.Config.DB == 2 { //sqlite
|
||||
dsn = proto.Config.SQLITE_FILE
|
||||
db, err = gorm.Open(sqlite.Open(dsn), &gorm.Config{})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
|
|||
16
dao/dbm.go
16
dao/dbm.go
|
|
@ -136,7 +136,6 @@ func FindDBRunHistoryByID(id uint) (proto.SQLRunHistory, error) {
|
|||
}
|
||||
return history, nil
|
||||
}
|
||||
|
||||
func FindDBRunHistoryByAuthID(auth_id int) ([]proto.SQLRunHistory, error) {
|
||||
var histories []proto.SQLRunHistory
|
||||
var db2 *gorm.DB
|
||||
|
|
@ -152,6 +151,21 @@ func FindDBRunHistoryByAuthID(auth_id int) ([]proto.SQLRunHistory, error) {
|
|||
return histories, nil
|
||||
}
|
||||
|
||||
func FindDBRunHistoryByAuthIDAndDbId(auth_id int, db_id uint) ([]proto.SQLRunHistory, error) {
|
||||
var histories []proto.SQLRunHistory
|
||||
var db2 *gorm.DB
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
db2 = DB.Debug()
|
||||
} else {
|
||||
db2 = DB
|
||||
}
|
||||
res := db2.Where("user_id = ? and db_id = ?", auth_id, db_id).Find(&histories)
|
||||
if res.Error != nil {
|
||||
return nil, res.Error
|
||||
}
|
||||
return histories, nil
|
||||
}
|
||||
|
||||
func DelSQLRunHistoryByID(id uint) error {
|
||||
var db2 *gorm.DB
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
|
|
|
|||
|
|
@ -78,9 +78,10 @@ type StructValue struct {
|
|||
}
|
||||
|
||||
type ConfigStruct struct {
|
||||
DB int `json:"db"` // 0: mysql, 1: pg
|
||||
DB int `json:"db"` // 0: mysql, 1: pg, 2:sqlite
|
||||
MYSQL_DSN string `json:"mysql_dsn"`
|
||||
PG_DSN string `json:"pg_dsn"`
|
||||
SQLITE_FILE string `json:"sqlite_file"`
|
||||
REDIS_ADDR string `json:"redis_addr"`
|
||||
TOKEN_USE_REDIS bool `json:"token_use_redis"`
|
||||
REDIS_User_PW bool `json:"redis_user_pw"` // 是否使用密码
|
||||
|
|
@ -169,6 +170,7 @@ func DefaultConfig() {
|
|||
Config.MYSQL_DSN = MYSQL_DSN
|
||||
Config.PG_DSN = ""
|
||||
Config.REDIS_ADDR = REDIS_ADDR
|
||||
Config.SQLITE_FILE = ""
|
||||
Config.TOKEN_USE_REDIS = false
|
||||
Config.REDIS_User_PW = false
|
||||
Config.REDIS_PASSWORD = REDIS_PASSWORD
|
||||
|
|
|
|||
|
|
@ -103,7 +103,11 @@ func GetSQLRunHistory(req *proto.GetSQLRunHistoryReq, userID int) ([]proto.SQLRu
|
|||
var err error
|
||||
|
||||
if req.GET_TYPE == 0 { // 获取自己的SQL执行历史
|
||||
historyList, err = dao.FindDBRunHistoryByAuthID(userID)
|
||||
if req.DB_ID > 0 {
|
||||
historyList, err = dao.FindDBRunHistoryByAuthIDAndDbId(userID, req.DB_ID)
|
||||
} else {
|
||||
historyList, err = dao.FindDBRunHistoryByAuthID(userID)
|
||||
}
|
||||
} else if req.GET_TYPE == 1 { // 管理员获取所有SQL执行历史
|
||||
user := GetUserByIDFromUserCenter(userID)
|
||||
if user.Role != "admin" {
|
||||
|
|
|
|||
Loading…
Reference in New Issue