Esempio n. 1
0
 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)
Esempio n. 2
0
 def delete(self, id):
     try:
         task = self.read(id)
         if task:
             with session.begin():
                 session.delete(task)
     except SQLAlchemyError as e:
         print(e)
Esempio n. 3
0
 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)
Esempio n. 4
0
 def read_list(cls):
     try:
         models = []
         with session.begin():
             query = session.query(cls)
             models = query.all()
         return models
     except SQLAlchemyError as e:
         print(e)
Esempio n. 5
0
 def create(self):
     try:
         with session.begin():
             session.add(self)
     except SQLAlchemyError as e:
         print(e)