def get_message_by_id(session: DBSession, *, message_id: int) -> DBMessage: db_message = session.query(DBMessage).filter( DBMessage.id == message_id).first() if db_message is None: raise DBMessageNotExists return db_message
def get_employee_by_id(session: DBSession, user_id: int) -> DBEmployee: try: user = session.query(DBEmployee).filter(DBEmployee.id == user_id).one() except NoResultFound: log.error("User is not found") raise DBNoResultException return user
def get_messages_by_recipient_id(session: DBSession, *, recipient_id: int) -> List[DBMessage]: db_messages = (session.query(DBMessage).filter( DBMessage.recipient_id == recipient_id).all() or []) return db_messages
def get_user_by_id(session: DBSession, *, user_id: int) -> DBUser: db_user = session.query(DBUser).filter(DBUser.id == user_id).first() if db_user is None: raise DBUserNotExists return db_user
def get_user_by_login(session: DBSession, *, login: str) -> DBUser: user = session.query(DBUser).filter(DBUser.login == login).first() if user is None: raise DBUserNotExists return user