当前位置: 首页>>代码示例>>Golang>>正文


Golang DB.Offset方法代码示例

本文整理汇总了Golang中github.com/jinzhu/gorm.DB.Offset方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Offset方法的具体用法?Golang DB.Offset怎么用?Golang DB.Offset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jinzhu/gorm.DB的用法示例。


在下文中一共展示了DB.Offset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AllMediaForDate

func AllMediaForDate(db gorm.DB, page, year, month, day int) []Media {
	var media []Media
	offset := (page - 1) * ResultsPerRequest
	scope := db.Offset(offset).Limit(ResultsPerRequest)

	if year > 0 {
		scope = scope.Where("date_part('year', taken_at) = ?", year)

		if month > 0 {
			scope = scope.Where("date_part('month', taken_at) = ?", month)

			if day > 0 {
				scope = scope.Where("date_part('day', taken_at) = ?", day)
			}
		}
	}
	scope.Find(&media)
	return media
}
开发者ID:jaischeema,项目名称:panorma,代码行数:19,代码来源:models.go

示例2: getJobsFromDB

func getJobsFromDB(db gorm.DB, start, limit int) (map[string]interface{}, int, error) {
	jobs := []application.Job{}
	jobsMap := make(map[string]interface{})
	var total int
	dbQuery := db.Offset(start)
	if limit > 0 {
		dbQuery = dbQuery.Limit(limit)
	}
	if err := dbQuery.Find(&jobs).Error; err != nil {
		return jobsMap, total, err
	}

	for _, job := range jobs {
		id := strconv.FormatUint(uint64(job.ID), 10)
		jobsMap[id] = job
	}

	if err := db.Find(&[]application.Job{}).Count(&total).Error; err != nil {
		return jobsMap, total, err
	}

	return jobsMap, total, nil
}
开发者ID:fairlance,项目名称:backend,代码行数:23,代码来源:database.go

示例3: getFreelancersFromDB

func getFreelancersFromDB(db gorm.DB, start, limit int) (map[string]interface{}, int, error) {
	freelancersMap := make(map[string]interface{})
	freelancers := []application.Freelancer{}
	var total int
	dbQuery := db.Offset(start)
	if limit > 0 {
		dbQuery = dbQuery.Limit(limit)
	}
	if err := dbQuery.Find(&freelancers).Error; err != nil {
		return freelancersMap, total, err
	}

	for _, freelancer := range freelancers {
		id := strconv.FormatUint(uint64(freelancer.ID), 10)
		freelancersMap[id] = freelancer
	}

	if err := db.Find(&[]application.Freelancer{}).Count(&total).Error; err != nil {
		return freelancersMap, total, err
	}

	return freelancersMap, total, nil
}
开发者ID:fairlance,项目名称:backend,代码行数:23,代码来源:database.go

示例4: PrepareQuery

func (p *QueryParams) PrepareQuery(searchRelation *gorm.DB) *gorm.DB {
	if len(p.Categories) != 0 && !contains(p.Categories, allCat) {
		searchRelation = searchRelation.Where("category_slug IN (?)", p.Categories)
	}

	if p.Page > 1 {
		searchRelation = searchRelation.Offset((p.Page - 1) * perPage)
	}

	if p.Sort == "newest" {
		searchRelation = searchRelation.Order("date desc")
	} else {
		searchRelation = searchRelation.Order("(total_views / POW(((EXTRACT(EPOCH FROM (now()-date)) / 3600)::integer + 2), 1.5)) desc")
	}

	if !p.StartDate.IsZero() {
		searchRelation = searchRelation.Where("date > ?", p.StartDate)
	}
	if !p.EndDate.IsZero() {
		searchRelation = searchRelation.Where("date < ?", p.EndDate)
	}

	return searchRelation.Limit(perPage)
}
开发者ID:rastasheep,项目名称:utisak-worker,代码行数:24,代码来源:query_params.go

示例5: LoadPhotos

func LoadPhotos(db *gorm.DB, start int, length int) []Photo {
	var photos []Photo
	db.Offset(start).Limit(length).Find(&photos)
	return photos
}
开发者ID:jaischeema,项目名称:gopic,代码行数:5,代码来源:queries.go

示例6: Unpaginate

func Unpaginate(db *gorm.DB) *gorm.DB {
	return db.Offset(-1).Limit(-1)
}
开发者ID:zannet,项目名称:confur-api,代码行数:3,代码来源:db_scopes.go


注:本文中的github.com/jinzhu/gorm.DB.Offset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。