Skip to content

Commit

Permalink
feat: set sqlalchemy_url through CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
reata committed Jan 7, 2024
1 parent b83aaf6 commit dc9dfe1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sqllineage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
NAME as MAIN_NAME,
VERSION as MAIN_VERSION,
)
from sqllineage.core.metadata.dummy import DummyMetaDataProvider
from sqllineage.core.metadata.sqlalchemy import SQLAlchemyMetaDataProvider
from sqllineage.drawing import draw_lineage_graph
from sqllineage.runner import LineageRunner
from sqllineage.utils.constant import LineageLevel
Expand Down Expand Up @@ -91,6 +93,11 @@ def main(args=None) -> None:
help="skip unsupported statements",
action="store_true",
)
parser.add_argument(
"--sqlalchemy_url",
help="sqlalchemy url to provide metadata for lineage analysis",
type=str,
)
args = parser.parse_args(args)
if args.e and args.f:
warnings.warn("Both -e and -f options are specified. -e option will be ignored")
Expand All @@ -99,6 +106,9 @@ def main(args=None) -> None:
runner = LineageRunner(
sql,
dialect=args.dialect,
metadata_provider=SQLAlchemyMetaDataProvider(args.sqlalchemy_url)
if args.sqlalchemy_url
else DummyMetaDataProvider(),
verbose=args.verbose,
draw_options={
"host": args.host,
Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_cli_dummy(_):
main(["-f", sql_file])
main(["-e", "select * from dual", "-f", sql_file])
main(["-f", sql_file, "-g"])
main(["-f", sql_file, "--silent_mode"])
main(["-f", sql_file, "--sqlalchemy_url=sqlite:///:memory:"])
break
main(["-g"])
main(["-ds"])
Expand Down

0 comments on commit dc9dfe1

Please sign in to comment.