本文整理匯總了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
}
示例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
}
示例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()
}
示例4: Query
// Query returns a new query for stories
func Query() *query.Query {
p := New()
return query.New(p.TableName, p.KeyName)
}
示例5: Query
// Query a new query relation referencing this model, optionally setting a default order
func Query() *query.Query {
return query.New("users", "id")
}
示例6: Query
// Query creates a new query relation referencing this model
func Query() *query.Query {
return query.New("images", "id")
}
示例7: Query
// Create a new query relation referencing this model
func Query() *query.Query {
return query.New("tags", "id")
}