优化
This commit is contained in:
parent
b4cc570e8a
commit
477d8fe6f9
|
@ -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) {
|
func PaginationToMap[T Model](ctx context.Context, q QueryCondition) (r []map[string]string, total int, err error) {
|
||||||
ctx = context.WithValue(ctx, "handle=>", "toMap")
|
return paginationToMap[T](globalBb, ctx, q)
|
||||||
ctx = context.WithValue(ctx, "map", &r)
|
|
||||||
_, total, err = pagination[T](globalBb, ctx, q)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
func PaginationToMapFromDB[T Model](db dbQuery, ctx context.Context, q QueryCondition) (r []map[string]string, total int, err error) {
|
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")
|
return paginationToMap[T](db, ctx, q)
|
||||||
ctx = context.WithValue(ctx, "map", &r)
|
|
||||||
_, total, err = pagination[T](db, ctx, q)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindOneById[T Model, I constraints.Integer](ctx context.Context, id I) (T, error) {
|
func FindOneById[T Model, I constraints.Integer](ctx context.Context, id I) (T, error) {
|
||||||
|
|
|
@ -563,7 +563,12 @@ func Test_paginationToMap(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
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 {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("paginationToMap() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("paginationToMap() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user