def read(cls, id): try: with session.begin(): task = session.query(cls).filter(cls.id == id).first() return task except SQLAlchemyError as e: print(e)
def delete(self, id): try: task = self.read(id) if task: with session.begin(): session.delete(task) except SQLAlchemyError as e: print(e)
def update(self, id): try: task = self.read(id) if task: with session.begin(): task.name = self.name task.text = self.text except SQLAlchemyError as e: print(e)
def read_list(cls): try: models = [] with session.begin(): query = session.query(cls) models = query.all() return models except SQLAlchemyError as e: print(e)
def create(self): try: with session.begin(): session.add(self) except SQLAlchemyError as e: print(e)