Exemplo n.º 1
0
def add_poll_vote(connection, username: str, vote_timestamp: float,
                  option_id: int):
    with get_cursor(connection) as cursor:
        cursor.execute(INSERT_VOTE, (username, option_id, vote_timestamp))
Exemplo n.º 2
0
def add_option(connection, option_text: str, poll_id: int):
    with get_cursor(connection) as cursor:
        cursor.execute(INSERT_OPTION_RETURNING_ID, (option_text, poll_id))
        option_id = cursor.fetchone()[0]
        return option_id
Exemplo n.º 3
0
def get_votes_for_option(connection, option_id: int) -> list[Vote]:
    with get_cursor(connection) as cursor:
        cursor.execute(SELECT_VOTES_FOR_OPTION, (option_id, ))
        return cursor.fetchall()
Exemplo n.º 4
0
def get_poll_options(connection, poll_id: int) -> list[Option]:
    with get_cursor(connection) as cursor:
        cursor.execute(SELECT_POLL_OPTIONS, (poll_id, ))
        return cursor.fetchall()
Exemplo n.º 5
0
def get_option(connection, option_id: int) -> Option:
    with get_cursor(connection) as cursor:
        cursor.execute(SELECT_OPTION, (option_id, ))
        return cursor.fetchone()
Exemplo n.º 6
0
def get_latest_poll(connection) -> Poll:
    with get_cursor(connection) as cursor:
        cursor.execute(SELECT_LATEST_POLL)
        return cursor.fetchone()
Exemplo n.º 7
0
def get_poll(connection, poll_id) -> Poll:
    with get_cursor(connection) as cursor:
        cursor.execute(SELECT_POLL, (poll_id, ))
        return cursor.fetchone()
Exemplo n.º 8
0
def get_polls(connection) -> list[Poll]:
    with get_cursor(connection) as cursor:
        cursor.execute(SELECT_ALL_POLLS)
        return cursor.fetchall()
Exemplo n.º 9
0
def create_poll(connection, title: str, owner: str):
    with get_cursor(connection) as cursor:
        cursor.execute(INSERT_POLLS_RETURN_ID, (title, owner))

        poll_id = cursor.fetchone()[0]
        return poll_id
Exemplo n.º 10
0
def create_tables(connection):
    with get_cursor(connection) as cursor:
        cursor.execute(CREATE_POLLS)
        cursor.execute(CREATE_OPTIONS)
        cursor.execute(CREATE_VOTES)