// 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 }
// 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 }
// 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 }
// 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 }
// 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 }
// 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 }
// 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 }
// 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 }
// WhereFeatured modifies the given query to select status Featured func WhereFeatured(q *query.Query) *query.Query { return q.Where("status = ?", Featured) }
// WhereSuspended modifies the given query to select status Suspended func WhereSuspended(q *query.Query) *query.Query { return q.Where("status = ?", Suspended) }
// WhereFinal modifies the given query to select status Final func WhereFinal(q *query.Query) *query.Query { return q.Where("status = ?", Final) }
// WhereDraft modifies the given query to select status draft func WhereDraft(q *query.Query) *query.Query { return q.Where("status = ?", Draft) }
// Order modifies the given query to order records by status func Order(q *query.Query) *query.Query { return q.Order("status desc") }
// 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") }
// WherePublished modifies the given query to select status Published func WherePublished(q *query.Query) *query.Query { return q.Where("status >= ?", Published) }
func Ordered(q *query.Query) *query.Query { return q.Order("name asc") }