utils.py 657 B

123456789101112131415161718192021222324
  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. return config[env]
  9. def truncate_target_db(conn, target_db) -> None:
  10. """ Truncates the target table
  11. """
  12. query = """
  13. SELECT count(1) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{target_db}'
  14. """.format(target_db=target_db)
  15. if conn.execute(text(query)).scalar() == 1:
  16. sql = """
  17. TRUNCATE TABLE {target_db}
  18. """.format(target_db=target_db)
  19. conn.execute(text(sql))