Skip to content

Commit

Permalink
0.2.0-beta4 (#20)
Browse files Browse the repository at this point in the history
* ## 0.2.0-beta3

* ## 0.2.0-beta4
  • Loading branch information
glennliao authored Jun 4, 2023
1 parent 0b96d1c commit b2285c7
Show file tree
Hide file tree
Showing 57 changed files with 307 additions and 218 deletions.
Empty file modified @doc/access.md
100644 → 100755
Empty file.
Empty file modified @doc/action.md
100644 → 100755
Empty file.
Empty file modified @doc/doc_ref.md
100644 → 100755
Empty file.
Empty file modified @doc/faq.md
100644 → 100755
Empty file.
Empty file modified @doc/functions.md
100644 → 100755
Empty file.
Empty file modified @doc/query.md
100644 → 100755
Empty file.
Empty file modified @doc/roadmap.md
100644 → 100755
Empty file.
Empty file modified @doc/v0.2.md
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified README.zh-CN.md
100644 → 100755
Empty file.
Empty file modified action/action.go
100644 → 100755
Empty file.
Empty file modified action/hook.go
100644 → 100755
Empty file.
65 changes: 33 additions & 32 deletions action/node.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ func newNode(key string, req []model.Map, structure *config.Structure, executor
Key: key, req: req, structure: structure, executor: executor,
}

n.Data = []model.Map{}
n.Where = []model.Map{}

// ?
for _ = range n.req {

n.Data = append(n.Data, model.Map{})
n.Where = append(n.Where, model.Map{})

}

if strings.HasSuffix(key, consts.ListKeySuffix) {
n.Key = key[0 : len(key)-len(consts.ListKeySuffix)]
n.IsList = true
Expand All @@ -51,13 +62,11 @@ func newNode(key string, req []model.Map, structure *config.Structure, executor

// parse req data to data/where
func (n *Node) parseReq(method string) {
n.Data = []model.Map{}
n.Where = []model.Map{}

for i, item := range n.req {

n.Data = append(n.Data, model.Map{})
n.Where = append(n.Where, model.Map{})
//n.Data = append(n.Data, model.Map{})
//n.Where = append(n.Where, model.Map{})

for key, val := range item {

Expand Down Expand Up @@ -101,8 +110,6 @@ func (n *Node) parse(ctx context.Context, method string) error {
n.tableName = access.Name
n.RowKey = access.RowKey

n.parseReq(method)

// 0. 角色替换

err = n.roleUpdate()
Expand Down Expand Up @@ -137,6 +144,8 @@ func (n *Node) parse(ctx context.Context, method string) error {
// 3. get where by accessCondition
err = n.whereUpdate(ctx, method, accessRoles)

n.parseReq(method)

return err
}

Expand Down Expand Up @@ -329,11 +338,12 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
return nil, err
}

var rowKeyVal model.Map
var rowKey string

switch method {
case http.MethodPost:

var rowKeyVal model.Map

access, err := n.action.actionConfig.GetAccessConfig(n.Key, true)
if err != nil {
return nil, err
Expand All @@ -358,30 +368,7 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
}
}

ret, err := executor.GetActionExecutor(n.executor).Do(ctx, executor.ActionExecutorReq{
Method: method,
Table: n.tableName,
Data: n.Data,
Where: nil,
})

if err != nil {
return nil, err
}

if len(n.Data) > 0 { //多条插入时返回值已经应该无意义了

jsonStyle := n.action.JsonFieldStyle
if rowKeyVal != nil {
for k, v := range rowKeyVal {
if k == consts.RowKey {
ret[jsonStyle(ctx, n.tableName, access.RowKey)] = v
} else {
ret[jsonStyle(ctx, n.tableName, k)] = v
}
}
}
}
rowKey = access.RowKey

case http.MethodPut:
case http.MethodDelete:
Expand All @@ -401,6 +388,20 @@ func (n *Node) do(ctx context.Context, method string) (ret model.Map, err error)
return nil, err
}

if len(n.Data) == 1 {

jsonStyle := n.action.JsonFieldStyle
if rowKeyVal != nil {
for k, v := range rowKeyVal {
if k == consts.RowKey {
ret[jsonStyle(ctx, n.tableName, rowKey)] = v
} else {
ret[jsonStyle(ctx, n.tableName, k)] = v
}
}
}
}

n.Ret = ret

err = EmitHook(ctx, AfterExecutorDo, n, method)
Expand Down
Empty file modified apijson.go
100644 → 100755
Empty file.
Empty file modified config/access.go
100644 → 100755
Empty file.
Empty file modified config/access_config.go
100644 → 100755
Empty file.
Empty file modified config/action_config.go
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions config/config.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func New() *Config {

func (c *Config) ReLoad() {

c.Access.accessConfigMap = make(map[string]AccessConfig)
accessConfigMap := make(map[string]AccessConfig)

ctx := context.Background()

Expand Down Expand Up @@ -108,10 +108,12 @@ func (c *Config) ReLoad() {
access.FieldsGet[role].MaxCount = &defaultMaxCount
}
}
c.Access.accessConfigMap[access.Alias] = access
accessConfigMap[access.Alias] = access
}
}

c.Access.accessConfigMap = accessConfigMap

requestListProvider := requestListProviderMap[c.RequestListProvider]
if requestListProvider != nil {
requestList := requestListProvider(ctx)
Expand Down
Empty file modified config/dbmeta.go
100644 → 100755
Empty file.
Empty file modified config/executor/action.go
100644 → 100755
Empty file.
Empty file modified config/executor/query.go
100644 → 100755
Empty file.
Empty file modified config/field.go
100644 → 100755
Empty file.
Empty file modified config/functions.go
100644 → 100755
Empty file.
Empty file modified config/query_config.go
100644 → 100755
Empty file.
Empty file modified config/request_config.go
100644 → 100755
Empty file.
Empty file modified config/rowkeygen.go
100644 → 100755
Empty file.
Empty file modified config/tables/table.go
100644 → 100755
Empty file.
Empty file modified consts/access.go
100644 → 100755
Empty file.
Empty file modified consts/errors.go
100644 → 100755
Empty file.
Empty file modified consts/node.go
100644 → 100755
Empty file.
142 changes: 0 additions & 142 deletions drivers/config/goframe/config.go

This file was deleted.

11 changes: 0 additions & 11 deletions drivers/executor/goframe/driver.go

This file was deleted.

21 changes: 21 additions & 0 deletions drivers/goframe/all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package goframe

import (
"github.com/glennliao/apijson-go/config"
"github.com/glennliao/apijson-go/config/executor"
gfConfig "github.com/glennliao/apijson-go/drivers/goframe/config"
gfExecutor "github.com/glennliao/apijson-go/drivers/goframe/executor"
)

func init() {

config.RegAccessListProvider(gfConfig.ProviderName, gfConfig.AccessListDBProvider)
config.RegRequestListProvider(gfConfig.ProviderName, gfConfig.RequestListProvider)

config.RegDbMetaProvider(gfConfig.ProviderName, gfConfig.DbMetaProvider)

executor.RegQueryExecutor("default", gfExecutor.New)
executor.RegActionExecutor("default", &gfExecutor.ActionExecutor{})

// todo 添加未配置driver时的报错信息, 而不是 invalid memory address or nil pointer dereference
}
Loading

0 comments on commit b2285c7

Please sign in to comment.