Skip to content

Commit f2497c9

Browse files
committed
fix: pagination Count is zero
1 parent 3401148 commit f2497c9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

kratos/orm/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Kratos ORM is a GORM for Kratos Framework.
44

55
- Support OpenTelemetry (`Statement.SkipHooks` skip the reporting if not recording)
66

7-
87
## Installation
98

109
### with cgo
@@ -22,3 +21,25 @@ $ go get -u gorm.io/driver/sqlite
2221
```shell
2322
$ go get -u github.com/glebarez/sqlite
2423
```
24+
25+
## Usage
26+
27+
### crud
28+
29+
```go
30+
type MyModel struct {
31+
ID int64
32+
Name string
33+
34+
crud.DBModel
35+
}
36+
37+
// or interface.
38+
type myRepo struct {
39+
crud.CRUD[MyModel]
40+
}
41+
42+
func NewMyRepo(db *gorm.DB) *myRepo {
43+
return &myRepo{crud.New(db)}
44+
}
45+
```

kratos/orm/crud/crud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ func (r *crud[T]) SelectList(ctx context.Context, pagination *protobuf.Paginatio
4444
err error
4545
)
4646
err = r.db.WithContext(ctx).Model(new(T)).
47+
Count(pagination.Count()).
4748
Offset(pagination.Offset()).
4849
Limit(pagination.Limit()).
49-
Count(pagination.Count()).
5050
Find(&list).Error
5151

5252
return list, err

0 commit comments

Comments
 (0)