mirror of
http://github.com/goal-web/database
synced 2025-12-24 10:40:53 +08:00
21 lines
532 B
Go
21 lines
532 B
Go
package table
|
|
|
|
import "github.com/goal-web/contracts"
|
|
|
|
func (table *Table) Chunk(size int, handler func(collection contracts.Collection, page int) error) (err error) {
|
|
page := 1
|
|
for err == nil {
|
|
newCollection := table.SimplePaginate(int64(size), int64(page))
|
|
err = handler(newCollection, page)
|
|
page++
|
|
if newCollection.Len() < size {
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (table *Table) ChunkById(size int, handler func(collection contracts.Collection, page int) error) error {
|
|
return table.OrderBy("id").Chunk(size, handler)
|
|
}
|