Пример #1
0
def read_by_id(id):
    """
    Read the user of the given ID.
    """

    try:
        session: Session = db_access.Session()
        return session.query(UserEntity).filter_by(id=id).first()
    except SQLAlchemyError as err:
        raise PersistenceError(
            f"Error on reading user by the ID {id}: {str(err)}") from err
Пример #2
0
def read_by_user_name(name):
    """
    Read the user of the given name.
    """

    try:
        session: Session = db_access.Session()
        return session.query(UserEntity).filter_by(user_name=name).first()
    except SQLAlchemyError as err:
        raise PersistenceError(
            f"Error on reading user by the user name {name}: {str(err)}"
        ) from err
Пример #3
0
def read_by_id(campaign_id: int) -> CampaignEntity:
    """
    Read campaign data by its ID.
    """

    try:
        session: Session = db_access.Session()
        return session.query(CampaignEntity).filter_by(id=campaign_id).first()
    except SQLAlchemyError as err:
        raise PersistenceError(
            f"Error on reading a campaign of the ID: {str(campaign_id)}"
        ) from err
def read_by_token(token):
    """
    Read a blacklisted token entry by the token value.
    """

    try:
        session = db_access.Session()
        blacklisted_token = session.query(BlacklistedTokenEntity).filter_by(
            token=token).first()
        return blacklisted_token
    except SQLAlchemyError as err:
        raise PersistenceError(
            f"Error on reading blacklisted token: {token}") from err
Пример #5
0
def read_all():
    """
    Read all users.
    """

    session: Session = db_access.Session()

    try:
        users = session.query(UserEntity).all()
        return users
    except SQLAlchemyError as err:
        raise PersistenceError(
            f"Error on reading all users: {str(err)}") from err
Пример #6
0
def read_by_gm_id(gm_id):
    """
    Get all campaigns belonging to the game master of the given ID.
    """

    try:
        session: Session = db_access.Session()
        return session.query(CampaignEntity).filter_by(
            game_master_id=gm_id).all()
    except SQLAlchemyError as err:
        raise PersistenceError(
            f"Error on reading campaigns of the GM (ID: {str(gm_id)}): {str(err)}"
        ) from err
Пример #7
0
def persist(campaign):
    """
    Persist the campaign data.
    """

    if not isinstance(campaign, CampaignEntity):
        raise ValueError("The argument is not CampaignEntity!")

    try:
        session: Session = db_access.Session()
        session.add(campaign)
        session.flush()
        return campaign
    except SQLAlchemyError as err:
        raise PersistenceError(f"Error on persisting a campaign: {str(err)}")
def persist(blacklisted_token):
    """
    Persist the given blacklisted token in the database.
    """

    if not isinstance(blacklisted_token, BlacklistedTokenEntity):
        raise ValueError("The argument is not BlacklistedTokenEntity.")

    try:
        session = db_access.Session()
        session.add(blacklisted_token)
        session.flush()
        return blacklisted_token
    except SQLAlchemyError as err:
        raise PersistenceError(
            f"Error on persisting blacklisted token: {str(err)}")
Пример #9
0
def persist(user):
    """
    Persist the given user in the database.
    """

    if not isinstance(user, UserEntity):
        raise ValueError("The argument is not UserEntity.")

    try:
        session: Session = db_access.Session()
        session.add(user)
        session.flush()
        return user
    except SQLAlchemyError as err:
        raise PersistenceError("Error on persisting user: {}".format(
            str(err))) from err