def upsert(detail): if type(detail) == list: return list(map(lambda d: upsert(d), detail)) id = define_id(detail) entity = Datastore.upsert(KIND, detail, id=id) logger.debug('Upsert detail %s', id) return Datastore.entity_to_dict(entity)
def upsert(person): if type(person) == list: return list(map(lambda p: upsert(p), person)) id = define_id(person) entity = Datastore.upsert(KIND, person, id=id) logger.debug('Upsert person %s', id) return Datastore.entity_to_dict(entity)
def upsert(cluster): if type(cluster) == list: return list(map(lambda c: upsert(c), cluster)) id = define_id(cluster) entity = Datastore.upsert(KIND, cluster, id=id) logger.debug('Upsert cluster %s', id) return Datastore.entity_to_dict(entity)
def find(filters=[], order=[], offset=0, limit=None): entities = Datastore.find(KIND, filters=filters, order=order, offset=offset, limit=limit) details = list(map(lambda e: Datastore.entity_to_dict(e), entities)) return details
def current_date(): entities = Datastore.get_one_property(KIND, 'release_date', order=['-release_date'], limit=1) if len(entities) == 0: return '' return Datastore.entity_to_dict(entities[0]['release_date'])
def delete(detail): if type(detail) == list: return list(map(lambda d: delete(d), detail)) elif type(detail) == dict: id = define_id(detail) else: id = detail entity = Datastore.delete(KIND, id) logger.debug('delete %s', id) return Datastore.entity_to_dict(entity)
def delete(person): if type(person) == list: return list(map(lambda p: delete(p), person)) elif type(person) == dict: id = define_id(person) else: id = person entity = Datastore.delete(KIND, id) logger.debug('delete %s', id) return Datastore.entity_to_dict(entity)
def delete(cluster): if type(cluster) == list: return list(map(lambda c: delete(c), cluster)) elif type(cluster) == dict: id = define_id(cluster) else: id = cluster entity = Datastore.delete(KIND, id) logger.debug('delete %s', id) return Datastore.entity_to_dict(entity)
def find(filters=[], order=[], offset=0, limit=None): # persons = [] # age_filters = list(filter(lambda f: f['key'] == 'age', filters)) # if len(age_filters) > 0: # age_filters[0].split(',') entities = Datastore.find(KIND, filters=filters, order=order, offset=offset, limit=limit) persons = list(map(lambda e: Datastore.entity_to_dict(e), entities)) return persons
def count(filters=[]): return Datastore.count(KIND, filters=filters)
def find_by_government_no(government, no): id = _define_id(government, no) entity = Datastore.find_by_id(KIND, id) return Datastore.entity_to_dict(entity)
def find_by_id(id): entity = Datastore.find_by_id(KIND, id) return Datastore.entity_to_dict(entity)
def delete_by_no(person): if type(person) == list: return list(map(lambda p: delete_by_no(p), person)) entity = Datastore.find_one(KIND, 'no', person['no']) return Datastore.delete(KIND, entity.key.id)
def get_last_no(): nos = Datastore.get_one_property(KIND, 'no', order=['-no'], limit=1) if len(nos) == 0: return 0 return nos[0]['no']
def find_by_no(no): id = _define_id(no) entity = Datastore.find_by_id(KIND, id) return Datastore.entity_to_dict(entity)