当前位置: 首页>>代码示例>>Golang>>正文


Golang Query.Run方法代码示例

本文整理汇总了Golang中google/golang.org/appengine/datastore.Query.Run方法的典型用法代码示例。如果您正苦于以下问题:Golang Query.Run方法的具体用法?Golang Query.Run怎么用?Golang Query.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google/golang.org/appengine/datastore.Query的用法示例。


在下文中一共展示了Query.Run方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: executeItemQuery

func executeItemQuery(con *Context, q *datastore.Query, limit int, cursorStr string) ([]Item, string, error) {
	if cursor, err := datastore.DecodeCursor(cursorStr); err == nil {
		q = q.Start(cursor)
	}

	var is = make([]Item, 0, limit)
	var err error
	t := q.Run(con.C)
	for {
		var i Item
		_, err = t.Next(&i)
		if err == datastore.Done {
			break
		}

		is = append(is, i)
		if err != nil {
			con.Log.Errorf("Error fetching next item: %v", err)
			return nil, "", err
		}
	}

	var cursor datastore.Cursor
	if cursor, err = t.Cursor(); err == nil {
		return is, cursor.String(), nil
	}

	return nil, "", err
}
开发者ID:koffeinsource,项目名称:kaffeeshare,代码行数:29,代码来源:itemGAE.go

示例2: NewIter

func (cdb ComplaintDB) NewIter(q *datastore.Query) *ComplaintIterator {
	ci := ComplaintIterator{
		//CDB:   cdb,
		Query: q,
		Iter:  q.Run(cdb.Ctx()),
	}
	return &ci
}
开发者ID:skypies,项目名称:complaints,代码行数:8,代码来源:iterators.go

示例3: executeCallbackQuery

func executeCallbackQuery(con *Context, q *datastore.Query, limit int) ([]Callback, error) {
	var is = make([]Callback, 0, limit)
	var err error
	t := q.Run(con.C)
	for {
		var i Callback
		_, err = t.Next(&i)
		if err == datastore.Done {
			break
		}

		is = append(is, i)
		if err != nil {
			con.Log.Errorf("Error fetching next item: %v", err)
			return nil, err
		}
	}

	return is, nil
}
开发者ID:koffeinsource,项目名称:kaffeeshare,代码行数:20,代码来源:callbackGAE.go

示例4: Run

// Run runs the query.
func (g *Goon) Run(q *datastore.Query) *Iterator {
	return &Iterator{
		g: g,
		i: q.Run(g.Context),
	}
}
开发者ID:laco0416,项目名称:goon,代码行数:7,代码来源:query.go

示例5: handler

func handler(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)
	u := user.Current(c)
	log.Infof(c, "Got a visitor to the front page!") //keep log in the imports

	//Check if the request is before or after to create the right query
	//The GET requests for the stories will be based around the SubmitDateTime
	//Using "after" will return stories after a certain date from newest to oldest
	//Using "before" will return stories before a certain date from oldest to newest
	//Default is to use the latest 3 submissions

	afterDate := r.FormValue("after")
	beforeDate := r.FormValue("before")
	returnLimit := 3
	showPrevLink := false

	var q *datastore.Query

	if afterDate != "" {
		showPrevLink = true
		//Get the results in descending order for newest to oldest
		afterDate = strings.Replace(afterDate, "%20", " ", -1) //replace all %20 with " "
		ttime, err := time.Parse(DateTimeDatastoreFormat, afterDate)
		if err != nil {
			serveError(c, w, err)
			return
		}
		q = datastore.NewQuery(WebSubmissionEntityName).
			Filter("SubmitDateTime <", ttime).
			Order("-SubmitDateTime").
			Limit(returnLimit)
	} else if beforeDate != "" {
		showPrevLink = true
		//Get the results is ascending order from oldest to newest
		beforeDate = strings.Replace(beforeDate, "%20", " ", -1) //replace all %20 with " "
		ttime, err := time.Parse(DateTimeDatastoreFormat, beforeDate)
		if err != nil {
			serveError(c, w, err)
			return
		}
		q = datastore.NewQuery(WebSubmissionEntityName).
			Filter("SubmitDateTime >", ttime).
			Order("SubmitDateTime").
			Limit(returnLimit)

		//limit check at the beginning if less than the returnLimit redo from the beginning
		length, cerr := q.Count(c)
		if cerr != nil {
			serveError(c, w, cerr)
		}

		//TODO refactor to not duplicate the default query below
		if length < returnLimit {
			showPrevLink = false
			q = datastore.NewQuery(WebSubmissionEntityName).
				Order("-SubmitDateTime").
				Limit(returnLimit)
		}
	} else {
		q = datastore.NewQuery(WebSubmissionEntityName).
			Order("-SubmitDateTime").
			Limit(returnLimit)

	}

	//Populate the results struct and store the keys
	var pageCon PageContainer

	for t := q.Run(c); ; {
		var x WebSubmission
		key, err := t.Next(&x)
		if err == datastore.Done {
			break
		}
		if err != nil {
			//			serveError(c,w,err)
			fmt.Fprintf(w, "nope %v", err.Error())
			return
		}
		if u == nil {
			pageCon.Stories = append(pageCon.Stories, StoryListData{x, key, false})
		} else {
			pageCon.Stories = append(pageCon.Stories, StoryListData{x, key, u.String() == x.SubmitBy})
		}
	}

	//if we filled up the page with results there are probably more, build the
	//next page link
	length, cerr := q.Count(c)
	if cerr != nil {
		serveError(c, w, cerr)
	}
	if length == returnLimit {
		//get the submit datetime of the last story
		pageCon.AfterLink = pageCon.Stories[returnLimit-1].Story.SubmitDateTime.Format(DateTimeDatastoreFormat)
	}

	//If it was a prev page press reverse the result array to get it back into chronological order
	if length >= 1 && beforeDate != "" {
//.........这里部分代码省略.........
开发者ID:SiroDiaz,项目名称:csuf,代码行数:101,代码来源:main.go


注:本文中的google/golang.org/appengine/datastore.Query.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。