Пример #1
0
// 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
0
// 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
0
// 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
0
// 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
0
// 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
0
// 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
0
// 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
0
// 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
0
// WhereFeatured modifies the given query to select status Featured
func WhereFeatured(q *query.Query) *query.Query {
	return q.Where("status = ?", Featured)
}
Пример #10
0
// WhereSuspended modifies the given query to select status Suspended
func WhereSuspended(q *query.Query) *query.Query {
	return q.Where("status = ?", Suspended)
}
Пример #11
0
// WhereFinal modifies the given query to select status Final
func WhereFinal(q *query.Query) *query.Query {
	return q.Where("status = ?", Final)
}
Пример #12
0
// WhereDraft modifies the given query to select status draft
func WhereDraft(q *query.Query) *query.Query {
	return q.Where("status = ?", Draft)
}
Пример #13
0
// Order modifies the given query to order records by status
func Order(q *query.Query) *query.Query {
	return q.Order("status desc")
}
Пример #14
0
// 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
0
// WherePublished modifies the given query to select status Published
func WherePublished(q *query.Query) *query.Query {
	return q.Where("status >= ?", Published)
}
Пример #16
0
func Ordered(q *query.Query) *query.Query {
	return q.Order("name asc")
}