def del_by_obj_type(obj, type): """deletes any and all entities with given obj_id and type""" query = Relation.gql("WHERE obj_id = :1 AND type = :2", obj, type) for record in query: rpc = urlfetch.create_rpc() urlfetch.make_fetch_call(rpc, cmdurl + "/relation/type?%s/%s/null" % (type, obj), method="DELETE", headers={'sharedpass': sharedpass}) record.delete()
def delete(subj, type, obj): """deletes any and all entities with given subj_id, type, and obj_id""" query = Relation.gql("WHERE subj_id = :1 AND type = :2 and obj_id = :3", subj, type, obj) for record in query: rpc = urlfetch.create_rpc() urlfetch.make_fetch_call(rpc, cmdurl + '/relation/all?%s/%s/%s' % (type, obj, subj), method="DELETE", headers={'sharedpass': sharedpass}) record.delete()
def del_by_obj(obj): """deletes any and all entities with given obj_id""" query = Relation.gql("WHERE obj_id = :1", obj) for record in query: rpc = urlfetch.create_rpc() urlfetch.make_fetch_call(rpc, cmdurl + "/relation/obj?null/%s/null" % (obj), method="DELETE", headers={'sharedpass': sharedpass}) record.delete()
def create_unique(subj, type, obj): """creates relation with given subj_id, type, and obj_id, if not already present""" query = Relation.gql("WHERE subj_id = :1 AND type = :2 and obj_id = :3", subj, type, obj) if query.count() == 0: rpc = urlfetch.create_rpc() urlfetch.make_fetch_call(rpc, cmdurl + '/relation/?%s/%s/%s' % (type, obj, subj), method="PUT", headers={'sharedpass': sharedpass}) record = Relation(subj_id = subj, type = type, obj_id = obj) record.put()
def create_unique(subj, type, obj): """creates relation with given subj_id, type, and obj_id, if not already present""" query = Relation.gql("WHERE subj_id = :1 AND type = :2 and obj_id = :3", subj, type, obj) if query.count() == 0: rpc = urlfetch.create_rpc() urlfetch.make_fetch_call(rpc, cmdurl + '/relation/?%s/%s/%s' % (type, obj, subj), method="PUT", headers={'sharedpass': sharedpass}) record = Relation(subj_id=subj, type=type, obj_id=obj) record.put()
def getby_subj_obj_type(subj, obj, type): return Relation.gql("WHERE subj_id = :1 AND type = :2 and obj_id = :3", subj, type, obj)
def getby_subj_obj(subj, obj): """returns all relation entities with given subj_id and obj_id""" return Relation.gql("WHERE subj_id = :1 AND obj_id = :2", subj, obj)
def getby_obj_type(obj, type): """returns all relation entities with given obj, type""" return Relation.gql("WHERE obj_id = :1 AND type = :2", obj, type)
def getby_subj_type(subj, type): """returns all relation entities with given subj, type""" return Relation.gql("WHERE subj_id = :1 AND type = :2", subj, type)