diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-15 16:46:17 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-09-15 16:46:17 +0000 |
commit | 28cc22419e32a65fea2d1678400265b8cabc3aff (patch) | |
tree | ff9ac1991fd48490b21ef6aa9015a347a165e2d9 /sqlglot/__main__.py | |
parent | Initial commit. (diff) | |
download | sqlglot-28cc22419e32a65fea2d1678400265b8cabc3aff.tar.xz sqlglot-28cc22419e32a65fea2d1678400265b8cabc3aff.zip |
Adding upstream version 6.0.4.upstream/6.0.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/__main__.py')
-rw-r--r-- | sqlglot/__main__.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/sqlglot/__main__.py b/sqlglot/__main__.py new file mode 100644 index 0000000..25200c4 --- /dev/null +++ b/sqlglot/__main__.py @@ -0,0 +1,69 @@ +import argparse + +import sqlglot + +parser = argparse.ArgumentParser(description="Transpile SQL") +parser.add_argument("sql", metavar="sql", type=str, help="SQL string to transpile") +parser.add_argument( + "--read", + dest="read", + type=str, + default=None, + help="Dialect to read default is generic", +) +parser.add_argument( + "--write", + dest="write", + type=str, + default=None, + help="Dialect to write default is generic", +) +parser.add_argument( + "--no-identify", + dest="identify", + action="store_false", + help="Don't auto identify fields", +) +parser.add_argument( + "--no-pretty", + dest="pretty", + action="store_false", + help="Compress sql", +) +parser.add_argument( + "--parse", + dest="parse", + action="store_true", + help="Parse and return the expression tree", +) +parser.add_argument( + "--error-level", + dest="error_level", + type=str, + default="RAISE", + help="IGNORE, WARN, RAISE (default)", +) + + +args = parser.parse_args() +error_level = sqlglot.ErrorLevel[args.error_level.upper()] + +if args.parse: + sqls = [ + repr(expression) + for expression in sqlglot.parse( + args.sql, read=args.read, error_level=error_level + ) + ] +else: + sqls = sqlglot.transpile( + args.sql, + read=args.read, + write=args.write, + identify=args.identify, + pretty=args.pretty, + error_level=error_level, + ) + +for sql in sqls: + print(sql) |