-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.go
45 lines (39 loc) · 1.1 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gormpager
import "fmt"
type (
Options struct {
PageSizeUpperLimit uint
PageSizeLowerLimit uint
}
Page[T any] struct {
// CurrentPage is which page I am in
CurrentPage int64 `json:"current_page"`
// PageSize is how many items can I expect in Data
PageSize int64 `json:"page_size"`
// TotalEntries indicates how many data exists
TotalEntries int64 `json:"total_entries"`
// TotalPages is how many pages are in total
TotalPages int64 `json:"total_pages"`
// NextPage says what page is next from current page. If current page is the
// last, this data will return to first page
NextPage int64 `json:"next_page"`
// EntriesCount indicates how many data the current page contains
EntriesCount int64 `json:"entries_count"`
// Data is what was found in db
Data []T `json:"data"`
}
rawQuery struct {
sql string
vars []interface{}
}
)
func RawQuery(sql string, vars ...interface{}) *rawQuery {
return &rawQuery{
sql,
vars,
}
}
func (c *rawQuery) setOffsetLimit(offset, limit int) {
c.sql = fmt.Sprintf("%s OFFSET ? LIMIT ?;", c.sql)
c.vars = append(c.vars, offset, limit)
}