Skip to content

Commit

Permalink
updating example
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelarte committed Nov 12, 2024
1 parent 11fca8b commit 3d0e11d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ Gorm plugin to add pagination to your select queries

## 😍 How to install it

> go get github.com/manuelarte/pagorminator
> go get -u -v github.com/manuelarte/pagorminator
## 🎯 How to use it

```go
DB.Use(pagorminator.PaGormMinator{})
var products []*Products
// give me the first 10 products
pageRequest := pagorminator.PageRequestOf(0, 10)
db.Scopes(pagorminator.WithPagination(&pageRequest)).Find(&products)
pageRequest, err := pagorminator.PageRequest(0, 1)
DB.Clauses(&pageRequest).First(&products)
```

The plugin will populate the page request variable will the `total amounts` and `total pages` fields.
The plugin will calculate the total amount of elements so then the fields `total amounts` and `total pages` can be used too.

## 🎓 Examples

Expand Down
2 changes: 1 addition & 1 deletion examples/simple/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/manuelarte/pagorminator v0.0.0-20241109213332-29069dcc8d67 // indirect
github.com/manuelarte/pagorminator v0.0.0-20241112000751-11fca8bd8d58 // indirect
github.com/mattn/go-sqlite3 v1.14.24 // indirect
golang.org/x/text v0.20.0 // indirect
)
4 changes: 4 additions & 0 deletions examples/simple/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/manuelarte/pagorminator v0.0.0-20241109213332-29069dcc8d67 h1:HhZkJJJ8/xalo8HK4ENMG+7YsfvliSv8ALti4Sa2Y9s=
github.com/manuelarte/pagorminator v0.0.0-20241109213332-29069dcc8d67/go.mod h1:e7ZYAl1XwI3uc0rOXmfF4FToPSS+C65DM4sPXwRNkKs=
github.com/manuelarte/pagorminator v0.0.0-20241109224601-fc808b208359 h1:8zQ9n3/GtYu1ENvqZDhA0vprI7NrUdEap/I0A/nbhQE=
github.com/manuelarte/pagorminator v0.0.0-20241109224601-fc808b208359/go.mod h1:e7ZYAl1XwI3uc0rOXmfF4FToPSS+C65DM4sPXwRNkKs=
github.com/manuelarte/pagorminator v0.0.0-20241112000751-11fca8bd8d58 h1:0yPDhABEtlJf3IRkz+qPLJoM2d44APOMGo3gbd/bOe8=
github.com/manuelarte/pagorminator v0.0.0-20241112000751-11fca8bd8d58/go.mod h1:e7ZYAl1XwI3uc0rOXmfF4FToPSS+C65DM4sPXwRNkKs=
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func main() {

// Read
var products []*Product
pageRequest, _ := pagorminator.PageRequestOf(0, 1)
db.Scopes(pagorminator.WithPagination(pageRequest)).First(&products)
pageRequest, _ := pagorminator.PageRequest(0, 1)
db.Clauses(&pageRequest).First(&products)
for _, product := range products {
fmt.Printf("PageRequest: {Page: %d, Size: %d, TotalElements: %d, TotalPages: %d\n",
pageRequest.GetPage(), pageRequest.GetSize(), pageRequest.GetTotalElements(), pageRequest.GetTotalPages())
Expand Down

0 comments on commit 3d0e11d

Please sign in to comment.