From ad74d24ee25e8eb185deac907d9569eeb0858740 Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 9 Nov 2018 17:28:59 +0100 Subject: [PATCH] updated docs for pagination --- docs/concepts.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/concepts.md b/docs/concepts.md index 998c297cb..e28446052 100644 --- a/docs/concepts.md +++ b/docs/concepts.md @@ -14,7 +14,7 @@ The interface is defined as followed: type CRUDable interface { Create(*User) error ReadOne() error - ReadAll(*User) (interface{}, error) + ReadAll(*User, int) (interface{}, error) Update() error Delete() error } @@ -36,6 +36,19 @@ All functions should behave like this, if they create or update something, they instance. The only exception is `ReadAll()` which returns an interface. Usually this is an array, because, well you cannot make an array of a set type (If you know a way to do this, don't hesitate to drop me a message). +### Pagination + +When using the `ReadAll`-method, the second parameter contains the requested page. Your function should return only the number of results +corresponding to that page. The number of items per page is definied in the config as `service.pagecount` (Get it with `viper.GetInt("service.pagecount")`). + +These can be calculated in combination with a helper function, `getLimitFromPageIndex(pageIndex)` which returns +SQL-needed `limit` (max-length) and `offset` parameters. You can feed this function directly into xorm's `Limit`-Function like so: + +```go +lists := []List{} +err := x.Limit(getLimitFromPageIndex(pageIndex)).Find(&lists) +``` + ## Rights This interface defines methods to check for rights on structs. They accept a `User` as parameter and usually return a `bool`.