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


Golang datastore.DeleteMulti函数代码示例

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


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


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