本文整理汇总了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
}
示例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)))
}
示例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
}
示例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
}
示例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)
})
}
示例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)
}
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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
}
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}