updated docs for pagination
This commit is contained in:
parent
d232836423
commit
ad74d24ee2
1 changed files with 14 additions and 1 deletions
|
@ -14,7 +14,7 @@ The interface is defined as followed:
|
||||||
type CRUDable interface {
|
type CRUDable interface {
|
||||||
Create(*User) error
|
Create(*User) error
|
||||||
ReadOne() error
|
ReadOne() error
|
||||||
ReadAll(*User) (interface{}, error)
|
ReadAll(*User, int) (interface{}, error)
|
||||||
Update() error
|
Update() error
|
||||||
Delete() 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
|
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).
|
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
|
## Rights
|
||||||
|
|
||||||
This interface defines methods to check for rights on structs. They accept a `User` as parameter and usually return a `bool`.
|
This interface defines methods to check for rights on structs. They accept a `User` as parameter and usually return a `bool`.
|
||||||
|
|
Loading…
Reference in a new issue