-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
from argparse import ArgumentParser | ||
|
||
from sqlalchemy import create_engine | ||
|
||
from fk_graph import setup_data, get_graph | ||
from fk_graph.plotly_functions import run_app | ||
|
||
def main(): | ||
engine = create_engine("sqlite+pysqlite:///:memory:") | ||
setup_data(engine) | ||
graph = get_graph(engine, "table_a", 1) | ||
args = _parse_args() | ||
if args.demo: | ||
engine = create_engine("sqlite+pysqlite:///:memory:") | ||
setup_data(engine) | ||
elif args.connection_string: | ||
engine = create_engine(args.connection_string) | ||
graph = get_graph(engine, args.table, args.primary_key) | ||
run_app(graph) | ||
|
||
def _parse_args(): | ||
parser = ArgumentParser( | ||
prog="fk-graph", | ||
description="Visualise the graphs hidden within relational databases.", | ||
|
||
) | ||
parser.add_argument("--demo", action="store_true") | ||
parser.add_argument("--connection-string") | ||
parser.add_argument("--table", required=True) | ||
parser.add_argument("--primary-key", required=True) | ||
args = parser.parse_args() | ||
if ( | ||
(not args.demo and args.connection_string is None) | ||
or | ||
(args.demo and args.connection_string is not None) | ||
): | ||
parser.error( | ||
"Exactly one of --demo and --connection-string should be used.") | ||
return args |