Esempio n. 1
0
def increase_animal(engine, animal):
    engine = sa.create_engine(engine)
    with engine.begin() as connection:
        select = vote_results.select().where(vote_results.c.name == animal)
        results = connection.execute(select)
        id, _, votes = results.fetchone()

        new_votes = votes + 1
        update = (vote_results.update().values(votes=new_votes).where(
            vote_results.c.id == id))
        connection.execute(update)
Esempio n. 2
0
def make_vote(animal):
    engine = sa.create_engine("sqlite:///vote_db.sqlite")
    with engine.begin() as connection:
        select = vote_results.select().where(vote_results.c.name == animal)
        results = connection.execute(select)
        id, _, votes = results.fetchone()

        new_vote = votes + 1

        update = (vote_results.update().values(votes=new_vote).where(
            vote_results.c.id == id))
        connection.execute(update)
Esempio n. 3
0
def add_animal_vote(animal):
    """
    Функция для того чтобы принять название животного, найти его в базе и обновить значение (количество голосов)
    :param animal:
    :return:
    """

    # engine = sa.create_engine("sqlite:///scripts/my_db.sqlite")
    engine = sa.create_engine("sqlite:///my_db.sqlite")

    with engine.begin() as connection:
        select = vote_results.select().where(vote_results.c.name == animal)
        results = connection.execute(select)

        id, _, votes = results.fetchone()

        new_votes = votes + 1
        update = (vote_results.update().values(votes=new_votes).where(
            vote_results.c.id == id))
        connection.execute(update)
Esempio n. 4
0
import sqlalchemy as sa

from app.db import vote_results

if __name__ == "__main__":
    engine = sa.create_engine("sqlite:///my_db.sqlite")
    with engine.begin() as connection:
        select = vote_results.select().where(vote_results.c.name == "parrots")
        results = connection.execute(select)
        id, _, votes = results.fetchone()

        new_votes = votes + 1
        update = (vote_results.update().values(votes=new_votes).where(
            vote_results.c.id == id))
        connection.execute(update)