forked from glennliao/apijson-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.go
More file actions
executable file
·43 lines (33 loc) · 1.08 KB
/
executor.go
File metadata and controls
executable file
·43 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package query
import (
"context"
"github.com/glennliao/apijson-go/config"
"github.com/glennliao/apijson-go/consts"
"github.com/glennliao/apijson-go/model"
"github.com/samber/lo"
)
type QueryExecutor interface {
ParseCondition(conditions model.MapStrAny, accessVerify bool) error
ParseCtrl(ctrl model.Map) error
List(page int, count int) (list []model.Map, err error)
Count() (total int64, err error)
One() (model.Map, error)
SetEmptyResult()
}
type queryExecutorBuilder func(ctx context.Context, config *config.ExecutorConfig) (QueryExecutor, error)
var queryExecutorBuilderMap = map[string]queryExecutorBuilder{}
func RegExecutor(name string, e queryExecutorBuilder) {
queryExecutorBuilderMap[name] = e
}
func NewExecutor(name string, ctx context.Context, config *config.ExecutorConfig) (QueryExecutor, error) {
if name == "" {
name = "default"
}
if v, exists := queryExecutorBuilderMap[name]; exists {
return v(ctx, config)
}
return nil, consts.NewSysErr("query executor not found: " + name)
}
func QueryExecutorList() []string {
return lo.Keys(queryExecutorBuilderMap)
}