def get_by_id(self, id: int, *, raise_ex: bool = False) -> tp.Optional[T]: rv = self._session.query(self.__obj_cls__) \ .filter(self.__obj_cls__.id == id) \ .first() if not rv and raise_ex: raise ObjectNotFoundError(self.__obj_cls__, 'id') return rv
def get_by_email(self, email: str, *, raise_ex: bool = False) -> tp.Optional[User]: rv = self._session.query(User).filter(User.email == email).first() if not rv and raise_ex: raise ObjectNotFoundError(User, 'email') return rv
def get_by_name_id(self, name_id: UUID, *, raise_ex: bool = False) -> tp.Optional[Person]: rv = self._session.query(Person).join(Name) \ .filter(Name.uid == name_id) \ .first() if not rv and raise_ex: raise ObjectNotFoundError(Person, 'name_id') return rv
def get_by_date( self, date: datetime.date, *, raise_ex: bool = False ) -> tp.List[Event]: rv = self._session.query(Event) \ .filter(Event.date == date) \ .all() if not rv and raise_ex: raise ObjectNotFoundError(Event, 'date') return rv
def get_by_address_id( self, address_id: UUID, *, raise_ex: bool = False ) -> tp.List[Address]: rv = self._session.query(Event).join(Address) \ .filter(Address.uid == address_id) \ .all() if not rv and raise_ex: raise ObjectNotFoundError(Event, 'address_id') return rv
def get(self, *, raise_ex: bool = False) -> tp.Optional[T]: rv = self._session.query(self.__obj_cls__).first() if not rv and raise_ex: raise ObjectNotFoundError(self.__obj_cls__) return rv