Example #1
0
 def get(self, entity_id):
     with self.client.pipeline(transaction=True) as pipe:
         pipe.watch(hash(entity_id))
         return Entity(**({
             k.decode(): v.decode()
             for k, v in pipe.hgetall(hash(entity_id)).items()
         }))
Example #2
0
def init_database():
    """Initialize the database"""
    with APP.app_context():
        DB.drop_all()
        DB.create_all()
        # add a few entities
        for name in MOCK_DATA:
            entity = Entity(name)
            DB.session.add(entity)
        DB.session.commit()
Example #3
0
 def get_by_id(self, id):
     r = self.repository.get_by_id(id)
     entity = r and Entity(int(r[0]), r[1]) or Entity()
     return json.dumps(entity, cls=EntityJsonEncoder)
Example #4
0
 def get_all(self):
     entities = [Entity(int(x[0]), x[1]) for x in self.repository.get_all()]
     return json.dumps(entities, cls=EntityJsonEncoder)
Example #5
0
 def save(self, json_body):
     with transaction(repository=Repository) as session:
         body = json.loads(json_body)
         entity = Entity(entity_value=body['value'])
         return json.dumps(session.save(entity=entity),
                           cls=EntityJsonEncoder)
Example #6
0
 def get(self, id):
     response = self.client.select(space_name=self.space_id, key=id)
     return Entity(*response[0]) if response else Entity()
Example #7
0
 def update(self, entity):
     response = self.client.update(space_name=self.space_id,
                                   key=entity.e_id,
                                   op_list=[('=', 1, entity.e_val)])
     return Entity(*response[0]) if response else Entity()
Example #8
0
 def remove(self, id):
     response = self.client.delete(space_name=self.space_id,
                                   key=id,
                                   index=0)
     return Entity(*response[0]) if response else Entity()
Example #9
0
 def create(self, entity):
     return Entity(*self.client.insert(space_name=self.space_id,
                                       values=entity.to_tuple())[0])