func pagination(ex db.Executor, page int, perPage int) (*[]dashboardEntry, error) { var entries []dashboardEntry var err error var rows *sql.Rows offset := perPage * page if rows, err = ex.Query(paginationSQL, offset, perPage); err != nil { return &entries, err } defer rows.Close() for rows.Next() { var e dashboardEntry err = rows.Scan( &e.Name, &e.ThumbnailID, &e.Slug, &e.CreatedAt, ) if err != nil { log.Fatal(err) } entries = append(entries, e) } if err = rows.Err(); err != nil { log.Fatal(err) } return &entries, err }
func totalPages(ex db.Executor, perPage int) int { var count int err := ex.QueryRow(totalPagesSQL).Scan(&count) if err != nil { return 0 } return int(math.Ceil(float64(count) / float64(perPage))) }