mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-04-29 23:55:18 +08:00
refactor: code review
This commit is contained in:
@@ -19,7 +19,7 @@ const (
|
||||
func (dbType DbType) MetaDbName() string {
|
||||
switch dbType {
|
||||
case DbTypeMysql:
|
||||
return "information_schema"
|
||||
return "mysql"
|
||||
case DbTypePostgres:
|
||||
return "postgres"
|
||||
case DM:
|
||||
|
||||
@@ -34,6 +34,7 @@ func getMysqlDB(d *DbInfo) (*sql.DB, error) {
|
||||
// ---------------------------------- mysql元数据 -----------------------------------
|
||||
const (
|
||||
MYSQL_META_FILE = "metasql/mysql_meta.sql"
|
||||
MYSQL_DBS = "MYSQL_DBS"
|
||||
MYSQL_TABLE_INFO_KEY = "MYSQL_TABLE_INFO"
|
||||
MYSQL_INDEX_INFO_KEY = "MYSQL_INDEX_INFO"
|
||||
MYSQL_COLUMN_MA_KEY = "MYSQL_COLUMN_MA"
|
||||
@@ -55,7 +56,7 @@ func (md *MysqlDialect) GetDbServer() (*DbServer, error) {
|
||||
}
|
||||
|
||||
func (md *MysqlDialect) GetDbNames() ([]string, error) {
|
||||
_, res, err := md.dc.Query("SELECT SCHEMA_NAME AS dbname FROM SCHEMATA")
|
||||
_, res, err := md.dc.Query(GetLocalSql(MYSQL_META_FILE, MYSQL_DBS))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
--MYSQL_DBS 数据库名信息
|
||||
SELECT
|
||||
SCHEMA_NAME AS dbname
|
||||
FROM
|
||||
information_schema.SCHEMATA
|
||||
WHERE
|
||||
SCHEMA_NAME NOT IN ('mysql', 'information_schema', 'performance_schema')
|
||||
---------------------------------------
|
||||
--MYSQL_TABLE_INFO 表详细信息
|
||||
SELECT
|
||||
table_name tableName,
|
||||
|
||||
@@ -44,19 +44,18 @@ func (a *configAppImpl) GetPageList(condition *entity.Config, pageParam *model.P
|
||||
|
||||
func (a *configAppImpl) Save(ctx context.Context, config *entity.Config) error {
|
||||
if config.Id == 0 {
|
||||
if err := a.Insert(ctx, config); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
oldConfig := a.GetConfig(config.Key)
|
||||
if oldConfig.Permission != "all" && !strings.Contains(oldConfig.Permission, config.Modifier) {
|
||||
return errorx.NewBiz("您无权修改该配置")
|
||||
}
|
||||
|
||||
if err := a.UpdateById(ctx, config); err != nil {
|
||||
return err
|
||||
}
|
||||
return a.Insert(ctx, config)
|
||||
}
|
||||
|
||||
oldConfig := a.GetConfig(config.Key)
|
||||
if oldConfig.Permission != "all" && !strings.Contains(oldConfig.Permission, config.Modifier) {
|
||||
return errorx.NewBiz("您无权修改该配置")
|
||||
}
|
||||
|
||||
if err := a.UpdateById(ctx, config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cache.Del(SysConfigKeyPrefix + config.Key)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user