fix NPE
This commit is contained in:
parent
c6b8d29b61
commit
2be1b29234
@ -8,6 +8,9 @@
|
||||
package api2sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"git.zhangdeman.cn/zhangdeman/database"
|
||||
"git.zhangdeman.cn/zhangdeman/database/define"
|
||||
"testing"
|
||||
@ -27,5 +30,35 @@ func Test_execute_Run(t *testing.T) {
|
||||
}, []string{}); nil != err {
|
||||
panic(err.Error())
|
||||
}
|
||||
dbClient, _ := clientManager.GetDBClient("TEST_DATABASE")
|
||||
|
||||
dbClient.SetTableStructure(map[string][]*define.ColumnConfig{
|
||||
"project": []*define.ColumnConfig{
|
||||
&define.ColumnConfig{
|
||||
Column: "flag",
|
||||
Alias: "project_flag",
|
||||
Type: "string",
|
||||
},
|
||||
},
|
||||
})
|
||||
Exec.SetDatabaseClientManager(clientManager)
|
||||
res, err := Exec.List(context.Background(), &define.Api2SqlParam{
|
||||
DatabaseFlag: "TEST_DATABASE",
|
||||
Table: "project",
|
||||
ForceMaster: false,
|
||||
InputSql: "",
|
||||
TableSplitConfig: define.TableSplitConfig{},
|
||||
SqlType: consts.SqlTypeList,
|
||||
ColumnList: nil,
|
||||
Limit: 0,
|
||||
Offset: 0,
|
||||
ForceNoLimit: false,
|
||||
OrderField: "id",
|
||||
OrderRule: "desc",
|
||||
WithCount: false,
|
||||
ConditionList: nil,
|
||||
TableColumnConfig: nil,
|
||||
Tx: nil,
|
||||
})
|
||||
fmt.Println(res, err)
|
||||
}
|
||||
|
@ -15,12 +15,11 @@ import (
|
||||
"git.zhangdeman.cn/zhangdeman/database/abstract"
|
||||
"git.zhangdeman.cn/zhangdeman/database/define"
|
||||
"git.zhangdeman.cn/zhangdeman/serialize"
|
||||
"go.uber.org/zap"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -184,6 +183,7 @@ func (c *wrapperClient) GetMasterClient(ctx context.Context, dbFlag string) (*go
|
||||
if dbClient, err = c.GetDBClient(dbFlag); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dbClient.GetMaster(ctx), nil
|
||||
}
|
||||
|
||||
|
@ -257,6 +257,9 @@ func (dc *DBClient) SetTableStructure(tableConfigTable map[string][]*define.Colu
|
||||
dc.cacheTableStructureConfig.Enable = false
|
||||
}
|
||||
dc.lock.Lock()
|
||||
if nil == dc.tableStructureCache {
|
||||
dc.tableStructureCache = make(map[string][]*define.ColumnConfig)
|
||||
}
|
||||
for table, columnConfig := range tableConfigTable {
|
||||
dc.tableStructureCache[table] = columnConfig
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user