utils.py 714 B

1234567891011121314151617181920212223242526
  1. import yaml
  2. from sqlalchemy import text
  3. def load_config(env='test'):
  4. """ Loads the configuration file
  5. """
  6. with open('config.yaml', 'r') as f:
  7. config = yaml.load(f, Loader=yaml.FullLoader)
  8. print('loading config for env: {}'.format(env))
  9. return config[env]
  10. def truncate_target_db(conn, target_db) -> None:
  11. """ Truncates the target table
  12. """
  13. query = """
  14. SELECT count(1) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{target_db}'
  15. """.format(target_db=target_db)
  16. if conn.execute(text(query)).scalar() == 1:
  17. sql = """
  18. TRUNCATE TABLE {target_db}
  19. """.format(target_db=target_db)
  20. conn.execute(text(sql))