• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang datastore.NewQuery函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: CleanupDatastore

// CleanupDatastore is to remove all data in datastore
func CleanupDatastore(ctx context.Context, namespaces ...string) error {
	var dummy []interface{}
	logger := wcg.NewLogger(nil)
	logger.Debugf("[Fixture] --------- CleanupDatastore ---------")
	namespaceList := append(namespaces, "")
	for _, ns := range namespaceList {
		logger.Debugf("[Fixture] Cleanup: ns=%q", ns)
		var _ctx = ctx
		if ns != "" {
			_ctx, _ = appengine.Namespace(_ctx, ns)
		}
		err := wcg.RetryUntil(func() error {
			var keys []*datastore.Key
			var err error
			if keys, err = datastore.NewQuery("").KeysOnly().GetAll(_ctx, dummy); err != nil {
				return err
			}
			if err := datastore.DeleteMulti(_ctx, keys); err != nil {
				return err
			}
			count, _ := datastore.NewQuery("").KeysOnly().Count(_ctx)
			if count == 0 {
				return nil
			}
			return fmt.Errorf("Still have %d keys.", count)
		}, 10*time.Second, 100*time.Millisecond)
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:speedland,项目名称:service,代码行数:33,代码来源:fixture.go


示例2: cleanup

func cleanup(s *testerator.Setup) error {
	t := datastore.NewQuery("__kind__").KeysOnly().Run(s.Context)
	kinds := make([]string, 0)
	for {
		key, err := t.Next(nil)
		if err == datastore.Done {
			break
		}
		if err != nil {
			return err
		}
		kinds = append(kinds, key.StringID())
	}

	for _, kind := range kinds {
		q := datastore.NewQuery(kind).KeysOnly()
		keys, err := q.GetAll(s.Context, nil)
		if err != nil {
			return err
		}
		err = datastore.DeleteMulti(s.Context, keys)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:favclip,项目名称:testerator,代码行数:28,代码来源:datastore.go


示例3: Dump

// Dump exports entities from the context c using the specified Options o and
// writing the generated JSON representations to the io.Writer w. You can configure
// how the dump will run by using the Options parameter. If there is an error
// generating the output, or writting to the writer, it is returned. This method
// may return an error after writting bytes to w: the output is not buffered.
func Dump(c context.Context, w io.Writer, o *Options) error {
	var (
		comma        = []byte(",")
		openBracket  = []byte("[")
		closeBracket = []byte("]")
		lineFeed     = []byte("\n")
		indent       = "  "
	)

	w.Write(openBracket)
	count := 0
	last := 0
	batchSize := o.BatchSize
	if batchSize <= 0 {
		batchSize = 100
	}

	q := datastore.NewQuery(o.Kind).Limit(batchSize)
	for i := q.Run(c); ; {
		var e Entity
		k, err := i.Next(&e)
		e.Key = k
		if err == datastore.Done {
			log.Infof(c, "datastore.Done: last=%d, count=%d", last, count)
			if last == count || count-last < batchSize {
				break
			}
			// This 100 batch is done, but more can be found in the next one
			last = count
			cur, err := i.Cursor()
			if err != nil {
				return err
			}
			log.Infof(c, "restarting the query: cursor=%v", cur)
			i = datastore.NewQuery(o.Kind).Limit(batchSize).Start(cur).Run(c)
			continue
		}
		if err != nil {
			return err
		}
		if count > 0 {
			w.Write(comma)
			w.Write(lineFeed)
		}
		var b []byte
		if o.PrettyPrint {
			b, err = json.MarshalIndent(&e, "", indent)
		} else {
			b, err = json.Marshal(&e)
		}
		if err != nil {
			return err
		}
		w.Write(b)
		count++
	}
	w.Write(closeBracket)
	return nil
}
开发者ID:ronoaldo,项目名称:aetools,代码行数:64,代码来源:funcs.go


示例4: DeleteAll

// DeleteAll deletes across all roots
// DeleteAll deletes by kind alone.
func (fs *dsFileSys) DeleteAll() (string, error) {

	msg := ""
	{
		q := datastore.NewQuery(tfil).KeysOnly()
		var files []DsFile
		keys, err := q.GetAll(fs.Ctx(), &files)
		if err != nil {
			msg += "could not get file keys\n"
			return msg, err
		}
		if len(keys) >= 500 {
			msg += "limited to 500 files. REPEAT operation.\n"
			keys = keys[:500]
		}

		err = datastore.DeleteMulti(fs.Ctx(), keys)
		if err != nil {
			msg += "error deleting files\n"
			return msg, err
		}

		msg += spf("%v files deleted\n", len(keys))

	}

	{
		q := datastore.NewQuery(tdir).KeysOnly()
		var dirs []DsDir
		keys, err := q.GetAll(fs.Ctx(), &dirs)
		if err != nil {
			msg += "could not get dir keys\n"
			return msg, err
		}
		if len(keys) >= 500 {
			msg += "limited to 500 directories. REPEAT operation.\n"
			keys = keys[:500]
		}

		err = datastore.DeleteMulti(fs.Ctx(), keys)
		if err != nil {
			msg += "error deleting directories\n"
			return msg, err
		}

		msg += spf("%v directories deleted\n", len(keys))
	}

	err := memcache.Flush(fs.Ctx())
	if err != nil {
		msg += "error flushing memcache\n"
		return msg, err
	} else {
		msg += "memcache flushed \n"
	}

	return msg, nil
}
开发者ID:aarzilli,项目名称:tools,代码行数:60,代码来源:31_fs_impl_other.go


示例5: SubtreeByPath

// subtreeByPath retrieves a subdirectories of a given directory.
// It is relying on an indexed string property "Dir"
// containing a string representation of the full path.
//
// It might be fast for deep, uncached directory subtree,
// that have been saved in nested manner.
//
// However, it might not find recently added directories.
// Upon finding nothing, it therefore returns the
// "warning" fsi.EmptyQueryResult
//
// The func could easily be enhanced chunked scanning.
//
// It is currently used by ReadDir and by the test package.
// It is public for the test package.
func (fs *dsFileSys) SubtreeByPath(name string, onlyDirectChildren bool) ([]DsDir, error) {

	dir, bname := fs.SplitX(name)
	name = dir + common.Filify(bname)
	if !strings.HasSuffix(name, sep) {
		name += sep
	}

	var q *datastore.Query

	if onlyDirectChildren {
		q = datastore.NewQuery(tdir).
			Filter("Dir=", name).
			Order("Dir")
		//  Limit(4)
	} else {
		pathInc := IncrementString(name)
		q = datastore.NewQuery(tdir).
			Filter("Dir>=", name).
			Filter("Dir<", pathInc).
			Order("Dir")
	}

	// log.Printf("%v", q)

	var children []DsDir
	keys, err := q.GetAll(fs.Ctx(), &children)
	if err != nil {
		aelog.Errorf(fs.Ctx(), "Error getting all children of %v => %v", dir+bname, err)
		return children, err
	}

	if len(children) < 1 {
		return children, fsi.EmptyQueryResult
	}

	// Very evil: We filter out root node, since it's
	// has the same dir as the level-1 directories.
	keyRoot := datastore.NewKey(fs.Ctx(), tdir, fs.RootDir(), 0, nil)
	idxRoot := -1

	for i := 0; i < len(children); i++ {
		children[i].fSys = fs
		children[i].Key = keys[i]
		if keys[i].Equal(keyRoot) {
			// log.Printf("root idx %v", i)
			idxRoot = i
		}
	}

	if idxRoot > -1 {
		children = append(children[:idxRoot], children[idxRoot+1:]...)
	}

	return children, nil

}
开发者ID:aarzilli,项目名称:tools,代码行数:72,代码来源:low_level_dirs_query.go


示例6: example4

func example4() {
	// [START sort_order_example]
	// Order alphabetically by last name:
	q := datastore.NewQuery("Person").Order("LastName")

	// Order by height, tallest to shortest:
	q = datastore.NewQuery("Person").Order("-Height")
	// [END sort_order_example]
	_ = q
}
开发者ID:wuman,项目名称:golang-samples,代码行数:10,代码来源:queries.go


示例7: GetTestResultsForSubmission

func GetTestResultsForSubmission(ctx context.Context, w http.ResponseWriter, r *http.Request) (status int, err error) {
	if r.Method != "GET" {
		return http.StatusMethodNotAllowed, nil
	}

	// TODO(victorbalan): Check if user is company or if user is parent of result
	// else return http.StatusUnauthorized
	_, ok := passenger.FromContext(ctx)
	if !ok {
		return http.StatusUnauthorized, nil
	}

	submissionKey, err := datastore.DecodeKey(mux.Vars(r)["key"])
	if err != nil {
		return http.StatusNotFound, err
	}

	keys, err := datastore.NewQuery("").
		Ancestor(submissionKey).
		Filter("__key__ >", submissionKey).
		KeysOnly().
		GetAll(ctx, nil)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	if len(keys) == 0 {
		json.NewEncoder(w).Encode([]string{})
		return http.StatusOK, nil
	}

	switch keys[0].Kind() {
	case model.JunitTestResultKind:
		var results model.JunitTestResults
		_, err = datastore.NewQuery(keys[0].Kind()).
			Ancestor(submissionKey).
			GetAll(ctx, &results)
		if err != nil {
			return http.StatusInternalServerError, err
		}
		json.NewEncoder(w).Encode(results)
	case model.DiffTestResultKind:
		var results model.DiffTestResults
		_, err = datastore.NewQuery(keys[0].Kind()).
			Ancestor(submissionKey).
			GetAll(ctx, &results)
		if err != nil {
			return http.StatusInternalServerError, err
		}
		json.NewEncoder(w).Encode(results)
	default:
		w.Write([]byte("[]"))
	}
	return http.StatusOK, nil
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:54,代码来源:submission.go


示例8: getRelations

func getRelations(req *http.Request, username string) ([]Relation, []Relation, error) {
	ctx := appengine.NewContext(req)
	var Following, FollowingMe []Relation
	q := datastore.NewQuery("Relation")
	_, err := q.Filter("Follower =", username).Order("Following").GetAll(ctx, &Following)
	if err != nil {
		return []Relation{}, []Relation{}, err
	}
	q = datastore.NewQuery("Relation")
	_, err = q.Filter("Following =", username).Order("Follower").GetAll(ctx, &FollowingMe)
	if err != nil {
		return []Relation{}, []Relation{}, err
	}
	return Following, FollowingMe, nil
}
开发者ID:Saxleader,项目名称:fall2015,代码行数:15,代码来源:following.go


示例9: profile

func profile(res http.ResponseWriter, req *http.Request, ps httprouter.Params) {
	sd := sessionInfo(req)
	var user User
	user.UserName = ps.ByName("name")

	ctx := appengine.NewContext(req)

	//Get ppl they're following
	q := datastore.NewQuery("Follow").Filter("Follower =", user.UserName)
	var f []Follow
	_, err := q.GetAll(ctx, &f)
	if err != nil {
		panic(err)
	}
	for _, val := range f {
		user.Following = append(user.Following, val.Following)
	}

	//Get ppl they're followed by
	q2 := datastore.NewQuery("Follow").Filter("Following =", user.UserName)
	var f2 []Follow
	_, err2 := q2.GetAll(ctx, &f2)
	if err2 != nil {
		panic(err)
	}
	for _, val := range f2 {
		user.FollowedBy = append(user.FollowedBy, val.Follower)
	}

	//Get ppl they're following
	q3 := datastore.NewQuery("Follow").Filter("Follower =", sd.UserName)
	var f3 []Follow
	_, err = q3.GetAll(ctx, &f3)
	if err != nil {
		panic(err)
	}
	for _, val := range f3 {
		sd.Following = append(sd.Following, val.Following)
	}

	sd.FollowingUser = stringInSlice(user.UserName, sd.Following)
	if user.UserName == sd.UserName {
		sd.FollowingUser = true
	}
	sd.ViewingUser = user

	tpl.ExecuteTemplate(res, "profile.html", &sd)
}
开发者ID:nikhilbhanushali21,项目名称:Class191tRepo,代码行数:48,代码来源:main.go


示例10: projections

func projections(c context.Context, u User, days int) (int64, int64, error) {
	var projected, earned int64

	g := syncutil.Group{}

	g.Go(func() error {
		q := datastore.NewQuery("Task").
			Filter("Disabled = ", false).
			Filter("Assignee = ", u.Email)

		for t := q.Run(c); ; {
			var x Task
			_, err := t.Next(&x)
			if err == datastore.Done {
				return nil
			} else if err != nil {
				return err
			}

			log.Debugf(c, "Item worth %v every %v", x.Value, x.Period)

			projected += int64(float64(x.Value) * (float64(days) / float64(x.Period)))
		}
	})

	g.Go(func() error {
		q := datastore.NewQuery("LoggedTask").
			Filter("User = ", u.Key).
			Filter("Completed >=", time.Now().Add(-24*time.Hour*time.Duration(days)))

		for t := q.Run(c); ; {
			var x LoggedTask
			_, err := t.Next(&x)
			if err == datastore.Done {
				return nil
			} else if err != nil {
				return err
			}

			log.Debugf(c, "Logged task worth %v", x.Amount)

			earned += int64(x.Amount)
		}
	})
	g.Wait()

	return projected, earned, g.Err()
}
开发者ID:dustin,项目名称:sallingshome,代码行数:48,代码来源:main.go


示例11: getWord

func getWord(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	term := req.FormValue("term")

	q := datastore.NewQuery("Word").Order("Term").Filter("Term =", term)

	html := " "

	iterator := q.Run(ctx)

	for {
		var entity Word
		_, err := iterator.Next(&entity)
		if err == datastore.Done {
			break
		} else if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
		html += `<dt>` + entity.Term + `</dt>
				 <dd>` + entity.Def + `</dd>`
	}

	res.Header().Set("Content-Type", "text/html")
	fmt.Fprintln(res, `
	<dl>`+html+`<dl>
	<form method="POST" action="">
		Enter a term to see its definition <input type="text" name="term">
		<input type="submit">
	</form>
		`)
}
开发者ID:andybenavides,项目名称:CSCI-191T,代码行数:32,代码来源:datastorePut.go


示例12: TestAddLocation

func (s *TestSuite) TestAddLocation() {
	t := s.T()

	loc, err := json.Marshal(&Location{
		Name: "Cambridge Fresh Pond",
		Lat:  42.5,
		Lng:  -71.5,
	})
	assert.Nil(t, err, "Error marshalling Location into JSON: %v", err)

	req, err := s.inst.NewRequest("POST", "/add-location",
		ioutil.NopCloser(bytes.NewBuffer(loc)))
	require.Nil(t, err, "Error preparing request: %v", err)
	rec := httptest.NewRecorder()
	s.rt.ServeHTTP(rec, req)

	const expectedResponse = `{"addLocation":"success"}`
	assert.Equal(t, expectedResponse, string(rec.Body.Bytes()),
		"Expected response to be %s, got %s", expectedResponse, string(rec.Body.Bytes()))

	dbReq, err := s.inst.NewRequest("GET", "/", nil)
	require.Nil(t, err, "Error preparing request: %v", err)
	ctx := appengine.NewContext(dbReq)

	q := datastore.NewQuery("Location")
	numLocs, err := q.Count(ctx)
	require.Nil(t, err, "Error preparing request: %v", err)
	assert.Equal(t, 1, numLocs, "Expected number of locations to be 1, got %d", numLocs)
}
开发者ID:AndyHaskell,项目名称:testify-tutorial,代码行数:29,代码来源:api_test.go


示例13: TestAddLocationTestify

func TestAddLocationTestify(t *testing.T) {
	inst, err := aetest.NewInstance(
		&aetest.Options{StronglyConsistentDatastore: true})
	require.Nil(t, err, "Error creating aetest instance: %v", err)
	defer inst.Close()
	rt := initRouter()

	loc, err := json.Marshal(&Location{
		Name: "Cambridge Fresh Pond",
		Lat:  42.5,
		Lng:  -71.5,
	})
	assert.Nil(t, err, "Error marshalling Location into JSON: %v", err)

	req, err := inst.NewRequest("POST", "/add-location",
		ioutil.NopCloser(bytes.NewBuffer(loc)))
	require.Nil(t, err, "Error preparing request: %v", err)
	rec := httptest.NewRecorder()
	rt.ServeHTTP(rec, req)

	const expectedResponse = `{"addLocation":"success"}`
	assert.Equal(t, expectedResponse, string(rec.Body.Bytes()),
		"Expected response to be %s, got %s", expectedResponse, string(rec.Body.Bytes()))

	dbReq, err := inst.NewRequest("GET", "/", nil)
	require.Nil(t, err, "Error preparing request: %v", err)
	ctx := appengine.NewContext(dbReq)

	q := datastore.NewQuery("Location")
	numLocs, err := q.Count(ctx)
	require.Nil(t, err, "Error preparing request: %v", err)
	assert.Equal(t, 1, numLocs, "Expected number of locations to be 1, got %d", numLocs)
}
开发者ID:AndyHaskell,项目名称:testify-tutorial,代码行数:33,代码来源:api_test.go


示例14: handlePersonalPage

func handlePersonalPage(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	session := getSession(ctx, req)
	username := strings.SplitN(req.URL.Path, "/", 3)[2]
	if username == "" {
		http.Redirect(res, req, "/userslist", 302)
		return
	}
	q := datastore.NewQuery("Image").Filter("Username =", username)
	var images []Image
	q.GetAll(ctx, &images)
	key := datastore.NewKey(ctx, "List", username, 0, nil)
	var list List
	datastore.Get(ctx, key, &list)
	listItems := make([]string, 0)
	if strings.TrimSpace(list.List) != "" {
		listItems = strings.Split(list.List, "\n")
	}
	model := &personalModel{
		Session:   session,
		Username:  username,
		ListItems: listItems,
		Images:    images,
	}
	err := tpls.ExecuteTemplate(res, "personalpage", model)
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}
}
开发者ID:robertsturner52,项目名称:user-viewpoints,代码行数:30,代码来源:personal.go


示例15: LoadGlobalStats

func (cdb ComplaintDB) LoadGlobalStats() (*GlobalStats, error) {
	gs := GlobalStats{}

	fgs := []FrozenGlobalStats{}
	q := datastore.NewQuery(kGlobalStatsKind).Limit(10)

	if keys, err := q.GetAll(cdb.Ctx(), &fgs); err != nil {
		return nil, err
	} else if len(fgs) != 1 {
		return nil, fmt.Errorf("LoadGlobalStats: found %d, expected 1", len(fgs))
	} else {
		buf := bytes.NewBuffer(fgs[0].Bytes)
		err := gob.NewDecoder(buf).Decode(&gs)
		gs.DatastoreKey = keys[0].Encode() // Store this, so we can overwrite

		// Pick out the high water marks ...
		if len(gs.Counts) > 0 {
			iMaxComplaints, iMaxComplainers := 0, 0
			maxComplaints, maxComplainers := 0, 0
			for i, _ := range gs.Counts {
				if gs.Counts[i].NumComplaints > maxComplaints {
					iMaxComplaints, maxComplaints = i, gs.Counts[i].NumComplaints
				}
				if gs.Counts[i].NumComplainers > maxComplainers {
					iMaxComplainers, maxComplainers = i, gs.Counts[i].NumComplainers
				}
			}
			gs.Counts[iMaxComplaints].IsMaxComplaints = true
			gs.Counts[iMaxComplainers].IsMaxComplainers = true
		}

		return &gs, err
	}
}
开发者ID:skypies,项目名称:complaints,代码行数:34,代码来源:globalstats.go


示例16: TestCreateSpot

func TestCreateSpot(t *testing.T) {
	opt := aetest.Options{AppID: "t2jp-2015", StronglyConsistentDatastore: true}
	inst, err := aetest.NewInstance(&opt)
	defer inst.Close()
	input, err := json.Marshal(Spot{SpotName: "foo", Body: "bar"})
	req, err := inst.NewRequest("POST", "/edit/v1/spots", bytes.NewBuffer(input))
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}
	loginUser := user.User{Email: "[email protected]", Admin: false, ID: "111111"}
	aetest.Login(&loginUser, req)
	ctx := appengine.NewContext(req)
	res := httptest.NewRecorder()
	c := web.C{}
	spotCreateHandler(c, res, req)
	if res.Code != http.StatusCreated {
		t.Fatalf("Fail to request spots create, status code: %v", res.Code)
	}
	spots := []Spot{}
	_, err = datastore.NewQuery("Spot").Order("-UpdatedAt").GetAll(ctx, &spots)
	for i := 0; i < len(spots); i++ {
		t.Logf("SpotCode:%v", spots[i].SpotCode)
		t.Logf("SpotName:%v", spots[i].SpotName)
	}
	if spots[0].SpotName != "foo" {
		t.Fatalf("not expected value! :%v", spots[0].SpotName)
	}

}
开发者ID:yosukesuzuki,项目名称:t2tapp,代码行数:29,代码来源:main_test.go


示例17: requestAllImage

func requestAllImage(res http.ResponseWriter, req *http.Request, ps httprouter.Params) {
	//user has requested to see all images
	sess, _ := getSession(req) // get login info if exists.
	var sd Session
	json.Unmarshal(sess.Value, &sd)

	ctx := appengine.NewContext(req)
	var links []blobbedImage
	for t := datastore.NewQuery("Images").Run(ctx); ; { /// get all images in Images from datastore
		var x blobbedImage
		_, err := t.Next(&x)
		if err == datastore.Done {
			break
		}
		if err != nil {
			serveTemplateWithParams(res, req, "falure.html", "INTERNAL DATASTORE ERROR, IMAGE REQUEST FAILED\nERROR: "+err.Error())
			return
		}
		links = append(links, x)
	}

	sd.Viewing = links  // add the images to our session data.
	if sd.Email != "" { // do a quick logged in check.
		sd.LoggedIn = true
	} else {
		sd.LoggedIn = false
	}

	serveTemplateWithParams(res, req, "imageMulti.html", sd) // serve.
}
开发者ID:mediix,项目名称:CSci_191T_FALL2015,代码行数:30,代码来源:api.go


示例18: NewSampleQueryBuilderWithKind

// NewSampleQueryBuilderWithKind create new SampleQueryBuilder with specific kind.
func NewSampleQueryBuilderWithKind(kind string) *SampleQueryBuilder {
	q := datastore.NewQuery(kind)
	bldr := &SampleQueryBuilder{q: q}
	bldr.ID = &SampleQueryProperty{
		bldr: bldr,
		name: "__key__",
	}
	bldr.FooUrl = &SampleQueryProperty{
		bldr: bldr,
		name: "FooURL",
	}
	bldr.StartAt = &SampleQueryProperty{
		bldr: bldr,
		name: "Start",
	}
	bldr.LimitProperty = &SampleQueryProperty{
		bldr: bldr,
		name: "Limit",
	}
	bldr.CreatedAt = &SampleQueryProperty{
		bldr: bldr,
		name: "CreatedAt",
	}

	if plugger, ok := interface{}(bldr).(qbgutils.Plugger); ok {
		bldr.plugin = plugger.Plugin()
		bldr.plugin.Init("Sample")
	}
	return bldr
}
开发者ID:favclip,项目名称:qbg,代码行数:31,代码来源:model_query.go


示例19: fing

func fing(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
	ctx := appengine.NewContext(req)
	// get session
	memItem, err := getSession(req)
	if err != nil {
		log.Infof(ctx, "Attempt to see following from logged out user")
		http.Error(res, "You must be logged in", http.StatusForbidden)
		return
	}
	var sd SessionData
	if err == nil {
		// logged in
		json.Unmarshal(memItem.Value, &sd)
		sd.LoggedIn = true
	}
	// declare a variable of type user
	// initialize user with values from memcache item
	var user User
	json.Unmarshal(memItem.Value, &user)
	// Get followees
	// get the datastore key for the follower
	followerKey := datastore.NewKey(ctx, "Users", user.UserName, 0, nil)
	var XF []F
	_, err = datastore.NewQuery("Follows").Ancestor(followerKey).Project("Following").GetAll(ctx, &XF)
	log.Errorf(ctx, "here is type %T \n and value %v", XF, XF)
	if err != nil {
		log.Errorf(ctx, "error getting followees: %v", err)
		http.Error(res, err.Error(), 500)
		return
	}
	sd.Following = XF
	tpl.ExecuteTemplate(res, "follow.html", &sd)
}
开发者ID:RaviTezu,项目名称:GolangTraining,代码行数:33,代码来源:main.go


示例20: Remove

// Remove safely deletes an account and all its associated information in the datastore. This includes
// any objects that are descendants of the Account (i.e., a cascading delete).
func Remove(ctx context.Context, account *Account) error {

	return datastore.RunInTransaction(ctx, func(txCtx context.Context) error {

		acctKey := account.Key(txCtx)
		q := datastore.NewQuery("").
			Ancestor(acctKey).
			KeysOnly()

		if changed, err := HasChanged(txCtx, account); err != nil {
			return err
		} else if changed {
			return ErrConflict
		}

		keys, err := q.GetAll(txCtx, nil)
		if err != nil {
			return err
		}

		keys = append(keys, acctKey)
		return nds.DeleteMulti(txCtx, keys)

	}, nil)

}
开发者ID:the-information,项目名称:ori,代码行数:28,代码来源:account.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang datastore.Put函数代码示例发布时间:2022-05-28
下一篇:
Golang datastore.NewKey函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap