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.")
def save(self, model: object) -> object: with Session() as session: session.add(model) session.commit() session.refresh(model) return model
def delete(self, model) -> None: with Session() as session: session.delete(model) session.commit()
def read_by_id(self, id_: int) -> object: with Session() as session: return session.query(self.__type_model).filter_by(id_=id_).first()
def read_all(self) -> list: with Session() as session: return session.query(self.__type_model).all()
def save(self, model: BaseModel) -> BaseModel: with Session() as session: session.add(model) session.commit() session.refresh(model) return model
def read_all(self) -> list: with Session() as session: result = session.query(self.__type_model).order_by('id').all() return result