# Pagination
all pagination provided could be use by specifying the pagination `type` on the URL. as of now **only offset pagination can be written in inline style**
## Styles
### Default
the default style allow you to supply request on a single params named `query` with json format, example:
```
?type=offset&query={"offset": 0, "sort": {"age":"ASC", "name":"DESC"}}
```
### Inline
while inline style allow to supply request component on separate params, example:
```
?type=inline_offset&skip=0&take=10&filter=[["name", "=", "andy"],"and",["age", "=", "17"]]
```
## Cursor Pagination
cursor pagination allow us to get list of resource starting with certain element, in this case
by specifying the `id` of the resource. To use this type of pagination when requesting the resource you have to specify param of type and query as such:
```
?type=cursor&query={"id":"some-id", "limit": 10}
```
## Offset Pagination
offset pagination allow us to get list and skipping/shifting the starting point of the data being requested, To use this type of pagination when requesting the resource you have to specify param of type and query as such:
```
?type=offset&query={"offset": 0, "limit": 10}
```
or with **inline style**
```
?type=inline_offset&take=10&skip=0
```
## Where/Filter
You could filter the data being requested by using `where` field on the `query` param, as such
```
?type=offset&query={"offset": 0, "where": {"age":"17"}}
```
or in **inline style** with `filter` params:
```
?type=inline_offset&skip=0&take=10&filter=[["name", "=", "andy"]]
```
### AND operation
by default `where` will act as `AND` operation if it detects multiple filter:
```
?type=offset&query={"offset": 0, "where": {"age":"17", "name":"andy"}}
```
is sql equivalent of `WHERE age = 17 AND name = 'andy'`
you could also use `and` with **inline style** such as:
```
?type=inline_offset&skip=0&take=10&filter=[["name", "=", "andy"],"and",["age", "=", "17"]
```
### OR operation
To use Or operator you could wrap your filters with `or` field as such
```
?type=offset&query={"offset": 0, "where": {"or": {"age":"17", "name":"andy"}}}
```
is sql equivalent of `WHERE age = 17 OR name = 'andy'`
you could combine it with AND as such
```
?type=offset&query={"offset": 0, "where": {"or": {"age":"17", "name":"andy"}, "id":"123"}}
```
is sql equivalent of `WHERE (age = 17 OR name = 'andy') AND id = '123'`
you could also use `or` with **inline style** such as:
```
?type=inline_offset&skip=0&take=10&filter=[["name", "=", "andy"],"or",["name", "=", "budi"]
```
### Using operator
you could specify which operator by wrapping your filter with available filter, as such
```
?type=offset&query={"offset": 0, "where": {"neq": {"age":"17"}}}
```
is sql equivalent of `WHERE age != '17'`
or use `AND` or `OR` query as such
```
?type=offset&query={"offset": 0, "where": {"neq": {"age":"17"}, "name": "andy}}
```
or by using **inline style** such as:
```
?type=inline_offset&skip=0&take=10&filter=[["name", "=", "andy"]]
```
is sql equivalent of `WHERE age != '17' AND name 'andy'`
#### Available operator
* `eq`, `=`
* `neq`, `!=`
* `in`
* `nin`, not in
* `gt`, `>`
* `gte`, `>=`
* `lt`, `<`
* `lte`, `<=`
## Sort
You are able to reorder the data being requested by adding `sort` field into the `query` param as such:
```
?type=offset&query={"offset": 0, "sort": {"age":"ASC"}}
or with inline style:
?type=inline_offset&skip=0&take=10&sort=[{"selector": "age", "desc": false}]
```
you could also order by multiple fields
```
?type=offset&query={"offset": 0, "sort": {"age":"ASC", "name":"DESC"}}
or with inline style:
?type=inline_offset&skip=0&take=10&sort=[{"selector": "age", "desc": false}, {"selector": "name", "desc": true}]
```
## Group
group allow you to group data with the same value based on selected field
```
?type=offset&query={"limit": 10, "group_by": [{"selector": "age", "desc": false, "isExpanded": true}]
or with inline offset
?type=inline_offset&skip=0&take=10&group=[{"selector": "age", "desc": false, "isExpanded": true}]
```
will resulted on data such as:
```
{
"status": 200,
"message": "ok",
"next_url": "",
"count": 11,
"data": [
{
"count": 1,
"items": [
{
"name": "budi",
"age": 18,
}
],
"key": 17,
"summary": [
1
]
},
{
"count": 1,
"items": [
{
"name": "andy",
"age": 18,
}
],
"key": 18,
"summary": [
1
]
}
]
}
```
you could also create a group of group by specifying multiple group request such as:
```
?type=offset&query={"limit": 10, "group_by": [{"selector": "age", "desc": false, "isExpanded": true}, {"selector": "name", "desc": false, "isExpanded": true}]
or with inline offset
?type=inline_offset&skip=0&take=10&group=[{"selector": "age", "desc": false, "isExpanded": true}, {"selector": "name", "desc": false, "isExpanded": true}]
```
or if you only need the group but not the item within you could set `isExpanded` to false:
```
?type=offset&query={"limit": 10, "group_by": [{"selector": "age", "desc": false, "isExpanded": false}]
or with inline offset
?type=inline_offset&skip=0&take=10&group=[{"selector": "age", "desc": false, "isExpanded": false}]
```
will resulted in
```
{
"status": 200,
"message": "ok",
"next_url": "",
"count": 11,
"data": [
{
"count": 1,
"items": null,
"key": 17,
"summary": [
1
]
},
{
"count": 1,
"items": null,
"key": 18,
"summary": [
1
]
}
]
}
```
## Distinct
allow you to only show **one unique** for each field selected
```
?type=offset&query={"limit": 10, "distinct": ["name"]}
or with inline style
?type=inline_offset&skip=0&take=10&distinct=["name"]
```
multiple distinct:
```
?type=offset&query={"limit": 10, "distinct": ["name", "age"]}
or with inline style
?type=inline_offset&skip=0&take=10&distinct=["name", "age"]
```
## Select
allow you to only show/select certain fields you need
```
?type=offset&query={"limit": 10, "select": ["name"]}
or with inline style
?type=inline_offset&skip=0&take=10&select=["name"]
```