本文整理匯總了Golang中github.com/fragmenta/query.Query類的典型用法代碼示例。如果您正苦於以下問題:Golang Query類的具體用法?Golang Query怎麽用?Golang Query使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Query類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FindFirst
// FindFirst fetches the first result for this query
func FindFirst(q *query.Query) (*User, error) {
result, err := q.FirstResult()
if err != nil {
return nil, err
}
return NewWithColumns(result), nil
}
示例2: FindAll
// FindAll returns all results for this query
func FindAll(q *query.Query) ([]*Comment, error) {
// Fetch query.Results from query
results, err := q.Results()
if err != nil {
return nil, err
}
// Construct an array of comments constructed from the results
// We do things a little differently, as we have a tree of comments
// root comments are added to the list, others are held in another list
// and added as children to rootComments
var rootComments, childComments []*Comment
for _, cols := range results {
c := NewWithColumns(cols)
if c.Root() {
rootComments = append(rootComments, c)
} else {
childComments = append(childComments, c)
}
}
// Now walk through child comments, assigning them to their parent
// Walk through comments, adding those with no parent id to comments list
// and others to the parent comment in root comments
for _, c := range childComments {
found := false
for _, p := range rootComments {
if p.Id == c.ParentId {
p.Children = append(p.Children, c)
found = true
break
}
}
if !found {
for _, p := range childComments {
if p.Id == c.ParentId {
p.Children = append(p.Children, c)
break
}
}
}
}
return rootComments, nil
}
示例3: FindAll
// FindAll returns all results for this query
func FindAll(q *query.Query) ([]*Story, error) {
// Fetch query.Results from query
results, err := q.Results()
if err != nil {
return nil, err
}
// Return an array of stories constructed from the results
var stories []*Story
for _, cols := range results {
p := NewWithColumns(cols)
stories = append(stories, p)
}
return stories, nil
}
示例4: FindAll
// FindAll fetches all results for this query
func FindAll(q *query.Query) ([]*User, error) {
// Fetch query.Results from query
results, err := q.Results()
if err != nil {
return nil, err
}
// Return an array of pages constructed from the results
var userList []*User
for _, r := range results {
user := NewWithColumns(r)
userList = append(userList, user)
}
return userList, nil
}
示例5: FindAll
// FindAll returns all results for this query
func FindAll(q *query.Query) ([]*User, error) {
// Fetch query.Results from query
results, err := q.Results()
if err != nil {
return nil, err
}
// Return an array of users constructed from the results
var users []*User
for _, cols := range results {
p := NewWithColumns(cols)
users = append(users, p)
}
return users, nil
}
示例6: FindAll
// FindAll returns all results for this query
func FindAll(q *query.Query) ([]*Post, error) {
// Fetch query.Results from query
results, err := q.Results()
if err != nil {
return nil, err
}
// Return an array of posts constructed from the results
var posts []*Post
for _, cols := range results {
p := NewWithColumns(cols)
posts = append(posts, p)
}
return posts, nil
}
示例7: FindAll
// FindAll fetches all results for this query
func FindAll(q *query.Query) ([]*Image, error) {
// Fetch query.Results from query
results, err := q.Results()
if err != nil {
return nil, err
}
// Return an array of pages constructed from the results
var imageList []*Image
for _, r := range results {
image := NewWithColumns(r)
imageList = append(imageList, image)
}
return imageList, nil
}
示例8: FindAll
// Fetch all results for this query
func FindAll(q *query.Query) ([]*Tag, error) {
// Fetch query.Results from query
results, err := q.Results()
if err != nil {
return nil, err
}
// Return an array of pages constructed from the results
var tagList []*Tag
for _, r := range results {
tag := NewWithColumns(r)
tagList = append(tagList, tag)
}
return tagList, nil
}
示例9: WhereFeatured
// WhereFeatured modifies the given query to select status Featured
func WhereFeatured(q *query.Query) *query.Query {
return q.Where("status = ?", Featured)
}
示例10: WhereSuspended
// WhereSuspended modifies the given query to select status Suspended
func WhereSuspended(q *query.Query) *query.Query {
return q.Where("status = ?", Suspended)
}
示例11: WhereFinal
// WhereFinal modifies the given query to select status Final
func WhereFinal(q *query.Query) *query.Query {
return q.Where("status = ?", Final)
}
示例12: WhereDraft
// WhereDraft modifies the given query to select status draft
func WhereDraft(q *query.Query) *query.Query {
return q.Where("status = ?", Draft)
}
示例13: Order
// Order modifies the given query to order records by status
func Order(q *query.Query) *query.Query {
return q.Order("status desc")
}
示例14: NotNull
// NotNull modifies the given query to select records which do not have null status
func NotNull(q *query.Query) *query.Query {
return q.Where("status IS NOT NULL")
}
示例15: WherePublished
// WherePublished modifies the given query to select status Published
func WherePublished(q *query.Query) *query.Query {
return q.Where("status >= ?", Published)
}