From 3d0e11dbb1d969f907051fa4c60e380999e49aee Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Tue, 12 Nov 2024 01:13:08 +0100 Subject: [PATCH] updating example --- README.md | 9 +++++---- examples/simple/go.mod | 2 +- examples/simple/go.sum | 4 ++++ examples/simple/main.go | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index da93321..7f5d9a5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/simple/go.mod b/examples/simple/go.mod index 427468f..0eb9edf 100644 --- a/examples/simple/go.mod +++ b/examples/simple/go.mod @@ -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 ) diff --git a/examples/simple/go.sum b/examples/simple/go.sum index a4ce51c..b467cc8 100644 --- a/examples/simple/go.sum +++ b/examples/simple/go.sum @@ -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= diff --git a/examples/simple/main.go b/examples/simple/main.go index d0c6d60..56f718c 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -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())