Пример #1
0
//分页查询
func GetEpisodes(q *qbs.Qbs, page int, column string, value interface{}, order string, url string) ([]*Episode, *Pagination) {
	page -= 1
	if page < 0 {
		page = 0
	}

	var episode []*Episode
	var rows int64
	if column == "" {
		fmt.Println(ItemsPerPage)
		fmt.Println(page)
		rows = q.Count("episode")
		err := q.OrderByDesc(order).
			Limit(ItemsPerPage).Offset(page * ItemsPerPage).FindAll(&episode)
		if err != nil {
			fmt.Println(err)
		}
	} else {
		rows = q.WhereEqual(column, value).Count("episode")
		err := q.WhereEqual(column, value).OrderByDesc(order).
			Limit(ItemsPerPage).Offset(page * ItemsPerPage).FindAll(&episode)
		if err != nil {
			fmt.Println(err)
		}
	}
	fmt.Println(episode)
	url = url[:strings.Index(url, "=")+1]
	pagination := NewPagination(page, int(rows), url)

	return episode, pagination
}