mirror of
https://github.com/go-home-admin/toolset.git
synced 2025-12-24 13:37:52 +08:00
add: mysql&pgsql增加SimplePaginate
This commit is contained in:
@@ -220,6 +220,20 @@ func (orm *OrmMysqlTableName) Paginate(page int, limit int) (MysqlTableNameList,
|
||||
return list, total
|
||||
}
|
||||
|
||||
// SimplePaginate 不统计总数的分页
|
||||
func (orm *OrmMysqlTableName) SimplePaginate(page int, limit int) MysqlTableNameList {
|
||||
list := make([]*MysqlTableName, 0)
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * limit
|
||||
tx := orm.db.Offset(offset).Limit(limit).Find(&list)
|
||||
if tx.Error != nil {
|
||||
logrus.Error(tx.Error)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// FindInBatches find records in batches
|
||||
func (orm *OrmMysqlTableName) FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm.DB, batch int) error) *gorm.DB {
|
||||
return orm.db.FindInBatches(dest, batchSize, fc)
|
||||
|
||||
@@ -190,6 +190,21 @@ func (orm *Orm{orm_table_name}) Paginate(page int, limit int) ({orm_table_name}L
|
||||
return list, total
|
||||
}
|
||||
|
||||
// SimplePaginate 不统计总数的分页
|
||||
func (orm *Orm{orm_table_name}) Paginate(page int, limit int) {orm_table_name}List {
|
||||
list := make([]*{orm_table_name}, 0)
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
offset := (page - 1) * limit
|
||||
tx := orm.db.Offset(offset).Limit(limit).Find(&list)
|
||||
if tx.Error != nil {
|
||||
logrus.Error(tx.Error)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// FindInBatches find records in batches
|
||||
func (orm *Orm{orm_table_name}) FindInBatches(dest interface{}, batchSize int, fc func(tx *gorm.DB, batch int) error) *gorm.DB {
|
||||
return orm.db.FindInBatches(dest, batchSize, fc)
|
||||
|
||||
Reference in New Issue
Block a user