當前位置: 首頁>>代碼示例>>Golang>>正文


Golang query.Query類代碼示例

本文整理匯總了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
}
開發者ID:intfrr,項目名稱:sendto,代碼行數:9,代碼來源:users.go

示例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
}
開發者ID:rogeriomarques,項目名稱:gohackernews,代碼行數:49,代碼來源:comments.go

示例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
}
開發者ID:ibmendoza,項目名稱:gohackernews,代碼行數:18,代碼來源:stories.go

示例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
}
開發者ID:maqiv,項目名稱:gohackernews,代碼行數:18,代碼來源:users.go

示例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
}
開發者ID:intfrr,項目名稱:sendto,代碼行數:18,代碼來源:users.go

示例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
}
開發者ID:BobbWu,項目名稱:fragmenta-cms,代碼行數:18,代碼來源:posts.go

示例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
}
開發者ID:BobbWu,項目名稱:fragmenta-cms,代碼行數:18,代碼來源:images.go

示例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
}
開發者ID:BobbWu,項目名稱:fragmenta-cms,代碼行數:18,代碼來源:tags.go

示例9: WhereFeatured

// WhereFeatured modifies the given query to select status Featured
func WhereFeatured(q *query.Query) *query.Query {
	return q.Where("status = ?", Featured)
}
開發者ID:kennygrant,項目名稱:gohackernews,代碼行數:4,代碼來源:status.go

示例10: WhereSuspended

// WhereSuspended modifies the given query to select status Suspended
func WhereSuspended(q *query.Query) *query.Query {
	return q.Where("status = ?", Suspended)
}
開發者ID:kennygrant,項目名稱:gohackernews,代碼行數:4,代碼來源:status.go

示例11: WhereFinal

// WhereFinal modifies the given query to select status Final
func WhereFinal(q *query.Query) *query.Query {
	return q.Where("status = ?", Final)
}
開發者ID:kennygrant,項目名稱:gohackernews,代碼行數:4,代碼來源:status.go

示例12: WhereDraft

// WhereDraft modifies the given query to select status draft
func WhereDraft(q *query.Query) *query.Query {
	return q.Where("status = ?", Draft)
}
開發者ID:kennygrant,項目名稱:gohackernews,代碼行數:4,代碼來源:status.go

示例13: Order

// Order modifies the given query to order records by status
func Order(q *query.Query) *query.Query {
	return q.Order("status desc")
}
開發者ID:kennygrant,項目名稱:gohackernews,代碼行數:4,代碼來源:status.go

示例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")
}
開發者ID:kennygrant,項目名稱:gohackernews,代碼行數:4,代碼來源:status.go

示例15: WherePublished

// WherePublished modifies the given query to select status Published
func WherePublished(q *query.Query) *query.Query {
	return q.Where("status >= ?", Published)
}
開發者ID:kennygrant,項目名稱:gohackernews,代碼行數:4,代碼來源:status.go


注:本文中的github.com/fragmenta/query.Query類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。