diff --git a/console/commands/orm/mysql.go.text b/console/commands/orm/mysql.go.text index 21a5b5c..15914b9 100644 --- a/console/commands/orm/mysql.go.text +++ b/console/commands/orm/mysql.go.text @@ -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) diff --git a/console/commands/pgorm/pgsql.go.text b/console/commands/pgorm/pgsql.go.text index 1b18494..394a569 100644 --- a/console/commands/pgorm/pgsql.go.text +++ b/console/commands/pgorm/pgsql.go.text @@ -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)