// 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 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 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 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 }
// 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 }
// 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 }