def creade_db(engine): engine = sa.create_engine(engine) metadata.create_all(engine) with engine.begin() as connection: for i, animal in enumerate(['cats', 'dogs', 'parrots'], start=1): statement = vote_results.insert().values(id=i, name=animal, votes=0) connection.execute(statement)
def create(): engine = sa.create_engine('sqlite:///my_db.sqlite') metadata.create_all(engine) with engine.begin() as connection: for i, animal in enumerate(['cats', 'dogs', 'parrots'], start=1): statement = vote_results.insert().values( id=i, name=animal, votes=0 ) connection.execute(statement) print("\n********************************\n********* БАЗА СОЗДАНА *********\n********************************\n ")
from app.db import vote_results, metadata import sqlalchemy as sa if __name__ == "__main__": engine = sa.create_engine("sqlite:///vote_db.sqlite") metadata.create_all(engine) with engine.begin() as connection: for i, animal in enumerate(["cats", "dogs", "parrots"]): statement = vote_results.insert().values(id=i, name=animal, votes=0) connection.execute(statement)