where clause

main v1.0.19
alex 2023-11-26 00:24:27 +01:00
parent 930ef2120e
commit 39ef3fa9e5
1 changed files with 7 additions and 7 deletions

View File

@ -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 {
if whereQuery == nil {
return database.Limit(paginationLimit).
Offset(GetPageOffset(query.Page, paginationLimit)).
Order(orderBy).
Find(result)
}
return database.Limit(paginationLimit).
Offset(GetPageOffset(query.Page, paginationLimit)).
Where(whereQuery, args).
@ -43,13 +50,6 @@ func DbPageQuery(database *gorm.DB, query PageQuery, paginationLimit int, 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
// can be used like this: robots[start:end]
func GetPage(lenList int, page int, limit int) (start int, end int) {