123456789101112131415161718 |
- from pathlib import Path
- import sqlglot
- from sqlglot.optimizer import optimize
- def main():
- output_path = Path("sandbox/sql/converted")
- for file in Path("sandbox/sql/raw").glob("*.sql"):
- with file.open("r", encoding="latin-1") as frh:
- res = optimize(sqlglot.parse_one(frh.read(), read="tsql"))
- output_file = output_path / file.name
- with output_file.open("w", encoding="latin-1") as fwh:
- fwh.write(res.sql(dialect="tsql", pretty=True))
- if __name__ == "__main__":
- main()
|