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

Golang datastore.DeleteMulti函数代码示例

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

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



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

示例1: 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


示例2: purgeuserHandler

func purgeuserHandler(w http.ResponseWriter, r *http.Request) {
	ctx := req2ctx(r)
	cdb := complaintdb.NewDB(ctx)
	email := r.FormValue("email")

	str := fmt.Sprintf("(purgeuser for %s)\n", email)

	q := cdb.QueryAllByEmailAddress(email).KeysOnly()
	keys, err := q.GetAll(cdb.Ctx(), nil)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	str += fmt.Sprintf("purge: %d complaints found\n", len(keys))

	if r.FormValue("forrealz") == "1" {
		maxRm := 400
		for len(keys) > maxRm {
			if err := datastore.DeleteMulti(cdb.Ctx(), keys[0:maxRm-1]); err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			keys = keys[maxRm:]
		}
		str += "all deleted :O\n"
	}

	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte(fmt.Sprintf("OK, purge\n%s", str)))
}
开发者ID:skypies,项目名称:complaints,代码行数:31,代码来源:complaint-batch.go


示例3: 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


示例4: 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


示例5: DeleteMulti

func (d rdsImpl) DeleteMulti(ks []*ds.Key, cb ds.DeleteMultiCB) error {
	keys, err := dsMF2R(d.aeCtx, ks)
	if err == nil {
		err = datastore.DeleteMulti(d.aeCtx, keys)
	}
	return idxCallbacker(err, len(ks), func(_ int, err error) {
		cb(err)
	})
}
开发者ID:tetrafolium,项目名称:gae,代码行数:9,代码来源:raw_datastore.go


示例6: DeletAllGlobalStats

func (cdb ComplaintDB) DeletAllGlobalStats() error {
	fgs := []FrozenGlobalStats{}
	q := datastore.NewQuery(kGlobalStatsKind).KeysOnly()

	if keys, err := q.GetAll(cdb.Ctx(), &fgs); err != nil {
		return err
	} else {
		return datastore.DeleteMulti(cdb.Ctx(), keys)
	}
}
开发者ID:skypies,项目名称:complaints,代码行数:10,代码来源:globalstats.go


示例7: deleteAllIdioms

func (a *GaeDatastoreAccessor) deleteAllIdioms(c context.Context) error {
	keys, err := datastore.NewQuery("Idiom").KeysOnly().GetAll(c, nil)
	if err != nil {
		return err
	}

	err = a.unindexAll(c)
	if err != nil {
		return err
	}

	return datastore.DeleteMulti(c, keys)
}
开发者ID:Deleplace,项目名称:programming-idioms,代码行数:13,代码来源:dataAccessorGae.go


示例8: clearEventData

// clearEventData deletes all EventData entities and flushes cache.
func clearEventData(c context.Context) error {
	if err := cache.flush(c); err != nil {
		return err
	}
	q := datastore.NewQuery(kindEventData).
		Ancestor(eventDataParent(c)).
		KeysOnly()
	keys, err := q.GetAll(c, nil)
	if err != nil {
		return fmt.Errorf("clearEventData: %v", err)
	}
	return datastore.DeleteMulti(c, keys)
}
开发者ID:CadeLaRen,项目名称:ioweb2016,代码行数:14,代码来源:db.go


示例9: deleteSavedPosts

func deleteSavedPosts(c context.Context, key string) error {
	// flush db
	q := datastore.NewQuery(key).Ancestor(getParentKey(c, key)).KeysOnly()
	keys, err := q.GetAll(c, nil)
	if err != nil {
		return err
	}
	if err = datastore.DeleteMulti(c, keys); err != nil {
		return err
	}
	// flush cache
	return memcache.Delete(c, key)
}
开发者ID:jchorl,项目名称:til_newtab,代码行数:13,代码来源:server.go


示例10: example

func example() {
	// [START batch]
	// A batch put.
	_, err = datastore.PutMulti(ctx, []*datastore.Key{k1, k2, k3}, []interface{}{e1, e2, e3})

	// A batch get.
	var entities = make([]*T, 3)
	err = datastore.GetMulti(ctx, []*datastore.Key{k1, k2, k3}, entities)

	// A batch delete.
	err = datastore.DeleteMulti(ctx, []*datastore.Key{k1, k2, k3})
	// [END batch]
	_ = err
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:14,代码来源:entities.go


示例11: Delete

func (this *MainController) Delete() {
	err := datastore.RunInTransaction(this.AppEngineCtx, func(c context.Context) error {
		ks, err := datastore.NewQuery("Todo").KeysOnly().Ancestor(models.DefaultTodoList(c)).Filter("Done=", true).GetAll(c, nil)
		if err != nil {
			return err
		}
		return datastore.DeleteMulti(c, ks)
	}, nil)

	if err == nil {
		this.Data["json"] = nil
	} else {
		this.Data["json"] = err
	}
}
开发者ID:lamproae,项目名称:beegae,代码行数:15,代码来源:default.go


示例12: ClearNamespace

// ClearNamespace deletes every entry in a namespace
func ClearNamespace(con *Context, namespace string) error {
	namespace = strings.ToLower(namespace)
	q := datastore.NewQuery(itemTable).
		Filter("Namespace =", namespace).
		KeysOnly()

	k, err := q.GetAll(con.C, nil)
	if err != nil {
		return err
	}

	clearCache(con, namespace)

	con.Log.Infof("Going to delete %v items in the namespace %v", len(k), namespace)

	return datastore.DeleteMulti(con.C, k)
}
开发者ID:koffeinsource,项目名称:kaffeeshare,代码行数:18,代码来源:namespaceGAE.go


示例13: DeleteComplaints

func (cdb ComplaintDB) DeleteComplaints(keyStrings []string, ownerEmail string) error {
	keys := []*datastore.Key{}
	for _, s := range keyStrings {
		k, err := datastore.DecodeKey(s)
		if err != nil {
			return err
		}

		if k.Parent() == nil {
			return fmt.Errorf("key <%v> had no parent", k)
		}
		if k.Parent().StringID() != ownerEmail {
			return fmt.Errorf("key <%v> owned by %s, not %s", k, k.Parent().StringID(), ownerEmail)
		}
		keys = append(keys, k)
	}
	return datastore.DeleteMulti(cdb.Ctx(), keys)
}
开发者ID:skypies,项目名称:complaints,代码行数:18,代码来源:complaintdb.go


示例14: adminMarkPaid

func adminMarkPaid(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	action := r.FormValue("action")

	keys := make([]*datastore.Key, 0, len(r.Form["pay"]))
	for _, s := range r.Form["pay"] {
		k, err := datastore.DecodeKey(s)
		if err != nil {
			panic(err)
		}
		keys = append(keys, k)
	}

	if action == "Mark Paid" {
		tasks := make([]LoggedTask, len(keys))

		err := datastore.GetMulti(c, keys, tasks)
		if err != nil {
			panic(err)
		}

		now := time.Now().UTC()
		for i := range tasks {
			tasks[i].Paid = true
			tasks[i].PaidTime = now
		}

		_, err = datastore.PutMulti(c, keys, tasks)
		if err != nil {
			panic(err)
		}
	} else if action == "Delete" {
		err := datastore.DeleteMulti(c, keys)
		if err != nil {
			panic(err)
		}
	} else {
		panic("Unhandled action: " + action)
	}

	http.Redirect(w, r, "/admin/", 303)
}
开发者ID:dustin,项目名称:sallingshome,代码行数:43,代码来源:admin.go


示例15: DropAllFromRecord

func DropAllFromRecord(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
	res.Header().Set("Access-Control-Allow-Origin", "*") // Allow for outside access.

	// Get Parameters
	sinfo, _ := GetStorageInfo(req)
	if sinfo.Domain == "" {
		ServeJsonOfStruct(res, JsonOptions{
			Status: "Failure",
			Reason: "Missing Parameter Domain",
			Code:   http.StatusNotAcceptable,
		}, nil)
		return
	}

	q := datastore.NewQuery(RecordsTable).Filter("Domain =", sinfo.Domain).KeysOnly()

	ctx := appengine.NewContext(req) // Make Context

	recordKeys, qErr := q.GetAll(ctx, nil)
	if qErr != nil {
		ServeJsonOfStruct(res, JsonOptions{
			Status: "Failure",
			Reason: qErr.Error(),
			Code:   500,
		}, nil)
		return
	}

	delErr := datastore.DeleteMulti(ctx, recordKeys)
	if delErr != nil {
		ServeJsonOfStruct(res, JsonOptions{
			Status: "Failure",
			Reason: delErr.Error(),
			Code:   500,
		}, nil)
		return
	}

	ServeJsonOfStruct(res, JsonOptions{
		Status: "Success",
	}, nil)
}
开发者ID:johnRedden,项目名称:LabLogin-Backend,代码行数:42,代码来源:Records.go


示例16: CollectTokens

// CollectTokens runs a query against Datastore to find expired
// Tokens and deletes them.
func CollectTokens(ctx context.Context, w http.ResponseWriter, r *http.Request) (int, error) {
	keys, err := model.NewQueryForToken().
		Filter("Expiry <", time.Now()).
		KeysOnly().
		GetAll(ctx, nil)

	if err != nil {
		log.Warningf(ctx, "garbage collecting tokens failed: %s", err.Error())
		return http.StatusInternalServerError, err
	}

	err = datastore.DeleteMulti(ctx, keys)

	if err != nil {
		log.Warningf(ctx, "garbage collecting tokens failed: %s", err.Error())
		return http.StatusInternalServerError, err
	}

	return http.StatusOK, nil
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:22,代码来源:token.go


示例17: deletepost

func deletepost(rw http.ResponseWriter, req *http.Request) {
	c := appengine.NewContext(req)
	u := user.Current(c)
	s := req.FormValue("encoded_key")
	k, err := datastore.DecodeKey(s)
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}
	mypost := Post{}
	err = datastore.Get(c, k, &mypost)
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}
	if mypost.Author == u.String() {
		if mypost.OP {
			q := datastore.NewQuery("post").Ancestor(k).KeysOnly()
			keys, err := q.GetAll(c, struct{}{})
			if err != nil {
				http.Error(rw, err.Error(), http.StatusInternalServerError)
				return
			}
			err = datastore.DeleteMulti(c, keys)
			if err != nil {
				http.Error(rw, err.Error(), http.StatusInternalServerError)
				return
			}
		} else {
			err := datastore.Delete(c, k)
			if err != nil {
				http.Error(rw, err.Error(), http.StatusInternalServerError)
				return
			}
		}
		// 	http.Redirect(rw, req, "/view", http.StatusTemporaryRedirect)
		// } else {
		http.Redirect(rw, req, "/", http.StatusTemporaryRedirect)
	}
}
开发者ID:SiroDiaz,项目名称:csuf,代码行数:40,代码来源:BulletinBoard.go


示例18: handleRemove

func handleRemove(w http.ResponseWriter, r *http.Request, apiKey APIKey) *appError {
	if r.Method != "DELETE" {
		return &appError{nil, fmt.Sprintf("Invalid request method: %s", r.Method), 401}
	}

	c := appengine.NewContext(r)

	strChatID := r.FormValue("chatID")
	rmPath := r.FormValue("path")

	if rmPath == "" {
		return &appError{nil, "Missing path.", 401}
	}

	var fbChatID int64 = -1
	var chatKey *datastore.Key
	var err error

	if strChatID != "" {
		fbChatID, err = strconv.ParseInt(strChatID, 10, 64)
		if err != nil {
			return &appError{nil, "Bad chat ID", 400}
		}
		chatKeys, err := datastore.NewQuery("Chat").Filter("FacebookChatID =", fbChatID).
			KeysOnly().GetAll(c, nil)

		if err != nil {
			return &appError{err, "Datastore error: " + err.Error(), 400}
		} else if len(chatKeys) == 0 {
			return &appError{nil, "Bad chat ID", 400}
		}

		chatKey = chatKeys[0]
	} else {
		chatKey = nil
	}

	deleted := make([]Link, 0)
	keysToRemove, err := datastore.NewQuery("Link").
		Filter("Path =", rmPath).Filter("ChatKey =", chatKey).GetAll(c, &deleted)

	if len(keysToRemove) != 0 {
		newKeys := make([]*datastore.Key, len(keysToRemove))
		for i := range keysToRemove {
			newKeys[i] = datastore.NewIncompleteKey(c, "DeletedLink", nil)
		}

		err = datastore.RunInTransaction(c, func(tc context.Context) (err error) {
			_, err = datastore.PutMulti(c, newKeys, deleted)
			if err != nil {
				return
			}
			err = datastore.DeleteMulti(c, keysToRemove)
			return
		}, nil)

	}

	var resp RemoveResponse
	if err != nil {
		resp = RemoveResponse{
			false,
			0,
			err.Error(),
		}
	} else {
		resp = RemoveResponse{
			true,
			len(keysToRemove),
			"",
		}
	}

	respJSON, _ := json.Marshal(resp)
	w.Write(respJSON)
	return nil
}
开发者ID:jordonwii,项目名称:hms,代码行数:77,代码来源:api.go


示例19: DeleteMulti

// DeleteMulti wraps datastore.DeleteMulti
func (d *Driver) DeleteMulti(key []*datastore.Key) error {
	d.logOps(opDelete, len(key), "DeleteMulti")
	return datastore.DeleteMulti(d.ctx, key)
}
开发者ID:speedland,项目名称:service,代码行数:5,代码来源:datastore.go


示例20: DeleteMulti

func (d rdsImpl) DeleteMulti(ks []ds.Key, cb ds.DeleteMultiCB) error {
	err := datastore.DeleteMulti(d, dsMF2R(ks))
	return idxCallbacker(err, len(ks), func(_ int, err error) {
		cb(err)
	})
}
开发者ID:martiniss,项目名称:gae,代码行数:6,代码来源:raw_datastore.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang datastore.Get函数代码示例发布时间:2022-05-28
下一篇:
Golang datastore.Delete函数代码示例发布时间: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