Esempio n. 1
0
 def read_by_id(self, id: int) -> BaseModel:
     if isinstance(id, int):
         with Session() as session:
             result = session.query(
                 self.__type_model).filter_by(id=id).first()
         return result
     else:
         raise TypeError("ID must be an Integer.")
Esempio n. 2
0
 def save(self, model: object) -> object:
     with Session() as session:
         session.add(model)
         session.commit()
         session.refresh(model)
         return model
Esempio n. 3
0
 def delete(self, model) -> None:
     with Session() as session:
         session.delete(model)
         session.commit()
Esempio n. 4
0
 def read_by_id(self, id_: int) -> object:
     with Session() as session:
         return session.query(self.__type_model).filter_by(id_=id_).first()
Esempio n. 5
0
 def read_all(self) -> list:
     with Session() as session:
         return session.query(self.__type_model).all()
Esempio n. 6
0
 def save(self, model: BaseModel) -> BaseModel:
     with Session() as session:
         session.add(model)
         session.commit()
         session.refresh(model)
         return model
Esempio n. 7
0
 def read_all(self) -> list:
     with Session() as session:
         result = session.query(self.__type_model).order_by('id').all()
     return result