@@ -31,25 +31,18 @@ type SqlExecutor struct {
3131 // 是否最终为空结果, 用于node中中断数据获取
3232 WithEmptyResult bool
3333
34- noAccessVerify bool
35-
36- access * config.AccessConfig
37-
38- config * config.Config
34+ config * config.ExecutorConfig
3935}
4036
41- func New (ctx context.Context , noAccessVerify bool , role string , access * config. AccessConfig , config * config.Config ) (executor.QueryExecutor , error ) {
37+ func New (ctx context.Context , config * config.ExecutorConfig ) (executor.QueryExecutor , error ) {
4238
4339 return & SqlExecutor {
4440 ctx : ctx ,
45- Role : role ,
4641 Where : [][]any {},
4742 Columns : nil ,
4843 Order : "" ,
4944 Group : "" ,
5045 WithEmptyResult : false ,
51- noAccessVerify : noAccessVerify ,
52- access : access ,
5346 config : config ,
5447 }, nil
5548}
@@ -81,15 +74,15 @@ func (e *SqlExecutor) ParseCondition(conditions model.MapStrAny, accessVerify bo
8174 return nil
8275 }
8376
84- if e .noAccessVerify { // 可任意字段搜索
77+ if e .config . NoVerify { // 可任意字段搜索
8578 return nil
8679 }
8780
88- inFieldsMap := e .access .GetFieldsGetInByRole (e . Role )
81+ inFieldsMap := e .config .GetFieldsGetInByRole ()
8982
9083 dbStyle := e .config .DbFieldStyle
9184
92- tableName := e .access . Name
85+ tableName := e .config . TableName ()
9386
9487 for _ , where := range e .Where {
9588 k := dbStyle (e .ctx , tableName , where [0 ].(string ))
@@ -169,7 +162,7 @@ var exp = regexp.MustCompile(`^[\s\w][\w()]+`) // 匹配 field, COUNT(field)
169162func (e * SqlExecutor ) ParseCtrl (ctrl model.Map ) error {
170163
171164 fieldStyle := e .config .DbFieldStyle
172- tableName := e .access . Name
165+ tableName := e .config . TableName ()
173166 for k , v := range ctrl {
174167 // 使用;分割字段
175168 fieldStr := strings .ReplaceAll (gconv .String (v ), ";" , "," )
@@ -203,7 +196,7 @@ func (e *SqlExecutor) ParseCtrl(ctrl model.Map) error {
203196}
204197
205198func (e * SqlExecutor ) build () * gdb.Model {
206- tableName := e .access . Name
199+ tableName := e .config . TableName ()
207200 m := g .DB ().Model (tableName ).Ctx (e .ctx )
208201
209202 if e .Order != "" {
@@ -272,16 +265,16 @@ func (e *SqlExecutor) build() *gdb.Model {
272265
273266func (e * SqlExecutor ) column () []string {
274267
275- outFields := e .access .GetFieldsGetOutByRole (e . Role )
268+ outFields := e .config .GetFieldsGetOutByRole ()
276269
277- tableName := e .access . Name
270+ tableName := e .config . TableName ()
278271
279272 var columns []string
280273
281274 if e .Columns != nil {
282275 columns = e .Columns
283276 } else {
284- columns = e .config .DbMeta . GetTableColumns ( tableName )
277+ columns = e .config .TableColumns ( )
285278 }
286279
287280 var fields = make ([]string , 0 , len (columns ))
@@ -304,7 +297,7 @@ func (e *SqlExecutor) column() []string {
304297 }
305298
306299 // 过滤可访问字段
307- if e .noAccessVerify || lo .Contains (outFields , dbStyle (e .ctx , tableName , fieldName )) ||
300+ if e .config . NoVerify || lo .Contains (outFields , dbStyle (e .ctx , tableName , fieldName )) ||
308301 len (outFields ) == 0 /* 数据库中未设置, 则看成全部可访问 */ {
309302 fields = append (fields , column )
310303 }
0 commit comments