parent
930ef2120e
commit
39ef3fa9e5
|
@ -36,6 +36,13 @@ type PageQuery struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DbPageQuery(database *gorm.DB, query PageQuery, paginationLimit int, result any, orderBy string, whereQuery interface{}, args ...interface{}) *gorm.DB {
|
func DbPageQuery(database *gorm.DB, query PageQuery, paginationLimit int, result any, orderBy string, whereQuery interface{}, args ...interface{}) *gorm.DB {
|
||||||
|
if whereQuery == nil {
|
||||||
|
return database.Limit(paginationLimit).
|
||||||
|
Offset(GetPageOffset(query.Page, paginationLimit)).
|
||||||
|
Order(orderBy).
|
||||||
|
Find(result)
|
||||||
|
}
|
||||||
|
|
||||||
return database.Limit(paginationLimit).
|
return database.Limit(paginationLimit).
|
||||||
Offset(GetPageOffset(query.Page, paginationLimit)).
|
Offset(GetPageOffset(query.Page, paginationLimit)).
|
||||||
Where(whereQuery, args).
|
Where(whereQuery, args).
|
||||||
|
@ -43,13 +50,6 @@ func DbPageQuery(database *gorm.DB, query PageQuery, paginationLimit int, result
|
||||||
Find(result)
|
Find(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DbPageQueryWithoutWhere(database *gorm.DB, query PageQuery, paginationLimit int, result any, orderBy string) *gorm.DB {
|
|
||||||
return database.Limit(paginationLimit).
|
|
||||||
Offset(GetPageOffset(query.Page, paginationLimit)).
|
|
||||||
Order(orderBy).
|
|
||||||
Find(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPage returns start and end for pagination
|
// GetPage returns start and end for pagination
|
||||||
// can be used like this: robots[start:end]
|
// can be used like this: robots[start:end]
|
||||||
func GetPage(lenList int, page int, limit int) (start int, end int) {
|
func GetPage(lenList int, page int, limit int) (start int, end int) {
|
||||||
|
|
Loading…
Reference in New Issue