def main(): control = Control("mysql+pymysql://root:root@localhost:8889/test") drop_all(control._engine) model.Base.metadata.create_all(control._engine) with control.session as session: create_tables(session) session.commit()
def connect(db_url, echo=False, drop_all=False): # Creates an engine using the database url engine = create_engine(db_url, echo=echo, pool_recycle=60) # drops the table if the variable is set to true if drop_all is True: _drop_all_.drop_all(engine) # Creates a new database using the engine object. Creates all columns and # tables. model.Base.metadata.create_all(engine) # Creates a new session that is bound to the engine object. Session = sessionmaker(bind=engine) return Session, engine
def control(): control = Control("sqlite:///", echo=False) drop_all(control._engine) Base.metadata.create_all(control._engine) return control