diff --git a/server/config/example-config.yaml b/server/config/example-config.yaml index 218b5d5e..641bb05b 100644 --- a/server/config/example-config.yaml +++ b/server/config/example-config.yaml @@ -4,4 +4,4 @@ web: # tasks_dir: # sqlitedb_file_path: # ip: -# port: 7001 # (production env), defaut is 9000 (test env) \ No newline at end of file +port: 9000 # (for test env, use 7001 in production env) \ No newline at end of file diff --git a/server/pkg/webserver/controller/gateway.go b/server/pkg/webserver/controller/gateway.go index 365dfa78..dd9c3bc5 100644 --- a/server/pkg/webserver/controller/gateway.go +++ b/server/pkg/webserver/controller/gateway.go @@ -35,6 +35,54 @@ type disConnectDBParams struct { Nsid string `json:"nsid"` } +func BatchExecNGQL(ctx iris.Context) base.Result { + params := new(batchExecNGQLParams) + err := ctx.ReadJSON(params) + if err != nil { + zap.L().Warn("execNGQLParams get fail", zap.Error(err)) + return base.Response{ + Code: base.Error, + Message: err.Error(), + } + } + nsid := ctx.GetCookie("nsid") + data := make([]map[string]interface{}, 0) + + for i := 0; i < len(params.Gqls); i++ { + gql := params.Gqls[i] + execute, _, err := dao.Execute(nsid, gql, make([]string, 0)) + gqlRes := make(map[string]interface{}) + gqlRes["gql"] = gql + if err != nil { + gqlRes["message"] = err.Error() + gqlRes["code"] = base.Error + } else { + gqlRes["code"] = base.Success + } + gqlRes["data"] = execute + data = append(data, gqlRes) + } + + if len(params.ParamList) > 0 { + execute, _, err := dao.Execute(nsid, "", params.ParamList) + gqlRes := make(map[string]interface{}) + gqlRes["gql"] = strings.Join(params.ParamList, "; ") + if err != nil { + gqlRes["message"] = err.Error() + gqlRes["code"] = base.Error + } else { + gqlRes["code"] = base.Success + } + gqlRes["data"] = execute + data = append(data, gqlRes) + } + + return base.Response{ + Code: base.Success, + Data: data, + } +} + func ExecNGQL(ctx iris.Context) base.Result { params := new(execNGQLParams) if err := ctx.ReadJSON(params); err != nil {