Пример #1
0
//GetFor returns a slice containing all the Actions for a given Model.
func GetFor(m gaemodel.Model, c appengine.Context) (as []*Action, err error) {
	is, err := gaemodel.GetByAncestor(c, typ, "Action", m.Key())
	if err != nil {
		return
	}
	as = is.([]*Action)
	return
}
Пример #2
0
//WasPerformedOn returns whether given client performed given ActionType on gived Model.
func WasPerformedOn(at ActionType, m gaemodel.Model, client string, c appengine.Context) (bool, error) {
	i := datastore.NewQuery("Action").Ancestor(m.Key()).Filter("Client =", client).Filter("Type =", at).KeysOnly().Run(c)
	_, err := i.Next(nil)
	if err == datastore.Done {
		return false, nil
	}
	return true, err
}
Пример #3
0
//DeleteFor deletes all Actions for a specified Model.
func DeleteFor(m gaemodel.Model, c appengine.Context) (err error) {
	var keys []*datastore.Key
	keys, err = datastore.NewQuery("Action").Ancestor(m.Key()).KeysOnly().GetAll(c, nil)
	if err != nil {
		return
	}
	err = datastore.DeleteMulti(c, keys)
	if err != nil {
		return
	}
	return
}
Пример #4
0
//Make creates a new Action using New and then saves it to Datastore.
func Make(m gaemodel.Model, at ActionType, client string, c appengine.Context) (a *Action, err error) {
	a = New(m.Key(), at, client)
	err = a.Save(c)
	return
}
Пример #5
0
//GetCountFor returns how many times given ActionType was performed on a Model.
func GetCountFor(at ActionType, m gaemodel.Model, c appengine.Context) (count int, err error) {
	count, err = datastore.NewQuery("Action").Ancestor(m.Key()).Filter("Type =", at).Count(c)
	return
}