Skip to content

Commit 6e026a6

Browse files
committed
fix(query): update total type
1 parent 4657117 commit 6e026a6

7 files changed

Lines changed: 15 additions & 11 deletions

File tree

action/hook.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package action
22

33
type Hook struct {
4+
// todo 区分 事务内和事务外的hook, 减少事务时长
45
Before func(n *Node, method string) error
56
After func(n *Node, method string) error
67
}

db/sqlexecutor.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,16 @@ func (e *SqlExecutor) column() []string {
282282
}
283283

284284
// 过滤可访问字段
285-
if !e.accessVerify || lo.Contains(outFields, dbStyle(e.ctx, tableName, fieldName)) {
285+
if !e.accessVerify || lo.Contains(outFields, dbStyle(e.ctx, tableName, fieldName)) ||
286+
len(outFields) == 0 /* 数据库中未设置, 则看成全部可访问 */ {
286287
fields = append(fields, column)
287288
}
288289
}
289290

290291
return fields
291292
}
292293

293-
func (e *SqlExecutor) List(page int, count int, needTotal bool) (list []g.Map, total int, err error) {
294+
func (e *SqlExecutor) List(page int, count int, needTotal bool) (list []g.Map, total int64, err error) {
294295

295296
if e.WithEmptyResult {
296297
return nil, 0, err
@@ -299,9 +300,11 @@ func (e *SqlExecutor) List(page int, count int, needTotal bool) (list []g.Map, t
299300
m := e.build()
300301

301302
if needTotal {
302-
total, err = m.Count()
303-
if err != nil || total == 0 {
303+
_total, err := m.Count()
304+
if err != nil || _total == 0 {
304305
return nil, 0, err
306+
} else {
307+
total = int64(_total)
305308
}
306309
}
307310

demo/todo/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/glennliao/apijson-go v0.0.0
7-
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.1
7+
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.2
88
github.com/gogf/gf/v2 v2.2.2
99
github.com/iancoleman/orderedmap v0.2.0
1010
github.com/samber/lo v1.33.0

demo/todo/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq
3131
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
3232
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
3333
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
34-
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.1 h1:O3GF8PIuvECnB0BdsJnVNj+KKYfsRpDTDl07rN4uczs=
35-
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.1/go.mod h1:z+/0qiOwMroAnj5ESuobTv0l5P83rf+XR3r6Fj8WJyk=
34+
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.2 h1:93FP18bid15qLeWmtAu184u1tp0dctQ06PBrJAyrdbc=
35+
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.2/go.mod h1:z+/0qiOwMroAnj5ESuobTv0l5P83rf+XR3r6Fj8WJyk=
3636
github.com/gogf/gf/v2 v2.0.0/go.mod h1:apktt6TleWtCIwpz63vBqUnw8MX8gWKoZyxgDpXFtgM=
3737
github.com/gogf/gf/v2 v2.2.2 h1:ew4k/VSr/gcPdMZcI8/HZYBYPjB0KOk6bQqA61M8bYE=
3838
github.com/gogf/gf/v2 v2.2.2/go.mod h1:thvkyb43RWUu/m05sRm4CbH9r7t7/FrW2M56L9Ystwk=

functions/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package functions
22

33
import "strings"
44

5-
// 解析ParseFunctionsStr字符串, 返回函数名和参数列表
5+
// ParseFunctionsStr 解析ParseFunctionsStr字符串, 返回函数名和参数列表
66
func ParseFunctionsStr(funcStr string) (functionsName string, paramKeys []string) {
77
if !strings.Contains(funcStr, "(") { // 无参形式
88
functionsName = funcStr

query/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type Node struct {
6161

6262
primaryTableKey string // 主查询表
6363

64-
total int // 数据总条数
64+
total int64 // 数据总条数
6565
needTotal bool
6666
}
6767

query/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func hasFirstUpKey(m g.Map) bool {
2828
return false
2929
}
3030

31-
// parseTableKey 解析表名
31+
// parseTableKey 解析表名 //todo 增加一个通用解析key的方法, 避免到处出现判断key后缀以及截取操作
3232
func parseTableKey(k string, p string) (tableName string) {
3333
tableName = k
3434

@@ -58,7 +58,7 @@ func parseQueryNodeReq(reqMap g.Map, isList bool) (refMap g.MapStrStr, where g.M
5858
} else {
5959
if isList {
6060
switch k {
61-
case "page", "count", "query":
61+
case "page", "count", "query": // todo 调整常量
6262
// 分页字段不传递到sqlExecutor
6363
continue
6464
}

0 commit comments

Comments
 (0)