浏览代码

SQL-Umwandlung (funktioniert noch nicht)

gc-server3 10 月之前
父节点
当前提交
706acb3675
共有 1 个文件被更改,包括 18 次插入0 次删除
  1. 18 0
      sandbox/sql_refactoring.py

+ 18 - 0
sandbox/sql_refactoring.py

@@ -0,0 +1,18 @@
+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()