/** * データストアの単語をすべて削除する * ajaxから呼び出すためのAPI */ func clear(w http.ResponseWriter, r *http.Request) { var c appengine.Context var u *user.User var keys []*datastore.Key var err error var query *datastore.Query var count int var entities []Entity c = appengine.NewContext(r) u = user.Current(c) query = datastore.NewQuery("words").Filter("UserID =", u.ID) count, err = query.Count(c) Check(c, err) entities = make([]Entity, count) keys, err = query.GetAll(c, &entities) Check(c, err) err = datastore.DeleteMulti(c, keys) Check(c, err) }
// Count returns the number of results for the query. func (g *Goon) Count(q *datastore.Query) (int, error) { return q.Count(g.Context) }
func GetCount(c appengine.Context, q *datastore.Query) (int, error) { return q.Count(c) }