當前位置: 首頁>>代碼示例>>Golang>>正文


Golang query.New函數代碼示例

本文整理匯總了Golang中github.com/fragmenta/query.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: storyHasUserFlag

// storyHasUserFlag returns true if we already have a flag for this story from this user
func storyHasUserFlag(story *stories.Story, user *users.User) bool {
	// Query flags table for rows with userId and storyId
	// if we don't get error, return true
	results, err := query.New("flags", "story_id").Where("story_id=?", story.Id).Where("user_id=?", user.Id).Results()
	if err == nil && len(results) == 0 {
		return false
	}

	return true
}
開發者ID:gnoirzox,項目名稱:gohackernews,代碼行數:11,代碼來源:votes.go

示例2: commentHasUserFlag

// commentHasUserFlag returns true if we already have a flag for this comment from this user
func commentHasUserFlag(comment *comments.Comment, user *users.User) bool {
	// Query flags table for rows with userId and commentId
	// if we don't get error, return true
	results, err := query.New("flags", "comment_id").Where("comment_id=?", comment.Id).Where("user_id=?", user.Id).Results()
	if err == nil && len(results) == 0 {
		return false
	}

	return true
}
開發者ID:gnoirzox,項目名稱:gohackernews,代碼行數:11,代碼來源:votes.go

示例3: HandleUpvoted

// HandleUpvoted displays a list of stories the user has upvoted in the past
func HandleUpvoted(context router.Context) error {

	// Build a query
	q := stories.Query().Limit(listLimit)

	// Select only above 0 points,  Order by rank, then points, then name
	q.Where("points > 0").Order("rank desc, points desc, id desc")

	// Select only stories which the user has upvoted
	user := authorise.CurrentUser(context)
	if !user.Anon() {
		// Can we use a join instead?
		v := query.New("votes", "story_id").Select("select story_id as id from votes").Where("user_id=? AND story_id IS NOT NULL AND points > 0", user.Id)

		storyIDs := v.ResultIDs()
		if len(storyIDs) > 0 {
			q.WhereIn("id", storyIDs)
		}
	}

	// Set the offset in pages if we have one
	page := int(context.ParamInt("page"))
	if page > 0 {
		q.Offset(listLimit * page)
	}

	// Fetch the stories
	results, err := stories.FindAll(q)
	if err != nil {
		return router.InternalError(err)
	}

	// Render the template
	view := view.New(context)
	setStoriesMetadata(view, context.Request())
	view.AddKey("page", page)
	view.AddKey("stories", results)
	view.Template("stories/views/index.html.got")

	if context.Param("format") == ".xml" {
		view.Layout("")
		view.Template("stories/views/index.xml.got")
	}

	return view.Render()

}
開發者ID:gnoirzox,項目名稱:gohackernews,代碼行數:48,代碼來源:upvoted.go

示例4: Query

// Query returns a new query for stories
func Query() *query.Query {
	p := New()
	return query.New(p.TableName, p.KeyName)
}
開發者ID:ibmendoza,項目名稱:gohackernews,代碼行數:5,代碼來源:stories.go

示例5: Query

// Query a new query relation referencing this model, optionally setting a default order
func Query() *query.Query {
	return query.New("users", "id")
}
開發者ID:maqiv,項目名稱:gohackernews,代碼行數:4,代碼來源:users.go

示例6: Query

// Query creates a new query relation referencing this model
func Query() *query.Query {
	return query.New("images", "id")
}
開發者ID:BobbWu,項目名稱:fragmenta-cms,代碼行數:4,代碼來源:images.go

示例7: Query

// Create a new query relation referencing this model
func Query() *query.Query {
	return query.New("tags", "id")
}
開發者ID:BobbWu,項目名稱:fragmenta-cms,代碼行數:4,代碼來源:tags.go


注:本文中的github.com/fragmenta/query.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。