Exemplo n.º 1
0
 def update_games(user_id: int, **kwargs) -> User:
     session = Session()
     user = session.query(User).filter(User.id.is_(user_id)).first()
     for key, value in kwargs.items():
         setattr(user, key, value)
     session.commit()
     session.close()
     return user
Exemplo n.º 2
0
    def add_user(username: str, password: str) -> User:
        # with Session as session:
        session = Session()

        username = username.lower()
        user = User(username, password)
        session.add(user)

        session.commit()
        session.close()
        return UserService.get_user(username=username)
Exemplo n.º 3
0
    def add_max(title: str, value: str) -> Maximum:
        # with Session as session:
        session = Session()

        maximum = Maximum(title, value)

        session.add(maximum)

        session.commit()
        session.close()
        return Maximum.get_max(title=title)
Exemplo n.º 4
0
    def get_user(id: int = None, username: str = None) -> User:
        session = Session()

        user: User = None

        if id:
            user = session.query(User).filter(User.id.is_(id)).first()
        elif username:
            username = username.lower()
            user = session.query(User).filter(User.username.is_(username)).first()

        session.close()
        return user
Exemplo n.º 5
0
    def get_max(id: int = None, title: str = None) -> Maximum:
        session = Session()

        maximum: Maximum = None

        if id:
            maximum = session.query(Maximum).filter(Maximum.id.is_(id)).first()
        elif title:
            maximum = session.query(Maximum).filter(
                Maximum.title.is_(title)).first()

        session.close()
        return maximum
Exemplo n.º 6
0
    def update_maximum(
        value: str,
        id: int = None,
        title: str = None,
    ) -> Maximum:
        session = Session()

        maximum: Maximum = None

        if id:
            maximum = session.query(Maximum).filter(Maximum.id.is_(id)).first()
        elif title:
            maximum = session.query(Maximum).filter(
                Maximum.title.is_(title)).first()

        if maximum:
            maximum.value = value
            session.commit()
        session.close()
Exemplo n.º 7
0
Session.commit()

#create a few users
user1 = User("test1", "*****@*****.**", "test123", 1, "Test", "Testovic",
             "+38762000000", 1, 1, "Testoo", usa.id)
user2 = User("test2", "*****@*****.**", "test123", 2, "Teston", "Testony",
             "+38565123123", 1, 1, "Testorony", canada.id)

Session.add(user1)
Session.add(user2)
Session.commit()

#create a few tiles
tile1 = Tile("023113001230003213130", 100.0, "Somewhere, Someplace, USA", 0, 1,
             0, datetime.utcnow(), usa.id, user1.id)
tile2 = Tile("023113001230003213132", 100.0, "Somewhere, Someplace, USA", 0, 1,
             0, datetime.utcnow(), usa.id, user1.id)
tile3 = Tile("023113001230003213131", 100.0, "Somewhere, Someplace, USA", 0, 1,
             0, datetime.utcnow(), usa.id, user1.id)
tile4 = Tile("023113001230003302020", 100.0, "Somewhere, Someplace, USA", 0, 1,
             0, datetime.utcnow(), usa.id, user1.id)

Session.add(tile1)
Session.add(tile2)
Session.add(tile3)
Session.add(tile4)
Session.commit()

#---------Commit to DB-------------
Session.close()