From 477d8fe6f9d990a18ff9fbcbbbdc95a7413e6911 Mon Sep 17 00:00:00 2001 From: xing Date: Sun, 26 Feb 2023 22:01:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/query.go | 10 ++-------- model/query_test.go | 7 ++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/model/query.go b/model/query.go index d5ea473..6e267dc 100644 --- a/model/query.go +++ b/model/query.go @@ -76,16 +76,10 @@ func paginationToMap[T Model](db dbQuery, ctx context.Context, q QueryCondition) } func PaginationToMap[T Model](ctx context.Context, q QueryCondition) (r []map[string]string, total int, err error) { - ctx = context.WithValue(ctx, "handle=>", "toMap") - ctx = context.WithValue(ctx, "map", &r) - _, total, err = pagination[T](globalBb, ctx, q) - return + return paginationToMap[T](globalBb, ctx, q) } func PaginationToMapFromDB[T Model](db dbQuery, ctx context.Context, q QueryCondition) (r []map[string]string, total int, err error) { - ctx = context.WithValue(ctx, "handle=>", "toMap") - ctx = context.WithValue(ctx, "map", &r) - _, total, err = pagination[T](db, ctx, q) - return + return paginationToMap[T](db, ctx, q) } func FindOneById[T Model, I constraints.Integer](ctx context.Context, id I) (T, error) { diff --git a/model/query_test.go b/model/query_test.go index e2aff9e..b588455 100644 --- a/model/query_test.go +++ b/model/query_test.go @@ -563,7 +563,12 @@ func Test_paginationToMap(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gotR, gotTotal, err := paginationToMap[post](tt.args.db, tt.args.ctx, tt.args.q) + gotR, gotTotal, err := PaginationToMap[post](tt.args.ctx, tt.args.q) + fmt.Println(gotR, gotTotal, err) + gotR, gotTotal, err = PaginationToMapFromDB[post](tt.args.db, tt.args.ctx, tt.args.q) + fmt.Println(gotR, gotTotal, err) + gotR, gotTotal, err = paginationToMap[post](tt.args.db, tt.args.ctx, tt.args.q) + if (err != nil) != tt.wantErr { t.Errorf("paginationToMap() error = %v, wantErr %v", err, tt.wantErr) return