Added --sql command to exportdb
This commit is contained in:
@@ -4808,6 +4808,11 @@ def run(python_file):
|
|||||||
is_flag=True,
|
is_flag=True,
|
||||||
help="Migrate (if needed) export database to current version.",
|
help="Migrate (if needed) export database to current version.",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--sql",
|
||||||
|
metavar="SQL_STATEMENT",
|
||||||
|
help="Execute SQL_STATEMENT against export database and print results.",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--export-dir",
|
"--export-dir",
|
||||||
help="Optional path to export directory (if not parent of export database).",
|
help="Optional path to export directory (if not parent of export database).",
|
||||||
@@ -4830,6 +4835,7 @@ def exportdb(
|
|||||||
save_config,
|
save_config,
|
||||||
info,
|
info,
|
||||||
migrate,
|
migrate,
|
||||||
|
sql,
|
||||||
export_dir,
|
export_dir,
|
||||||
verbose,
|
verbose,
|
||||||
dry_run,
|
dry_run,
|
||||||
@@ -4857,6 +4863,7 @@ def exportdb(
|
|||||||
bool(save_config),
|
bool(save_config),
|
||||||
bool(info),
|
bool(info),
|
||||||
migrate,
|
migrate,
|
||||||
|
bool(sql),
|
||||||
]
|
]
|
||||||
if sum(sub_commands) > 1:
|
if sum(sub_commands) > 1:
|
||||||
print(f"[red]Only a single sub-command may be specified at a time[/red]")
|
print(f"[red]Only a single sub-command may be specified at a time[/red]")
|
||||||
@@ -4975,6 +4982,19 @@ def exportdb(
|
|||||||
)
|
)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if sql:
|
||||||
|
exportdb = ExportDB(export_db, export_dir)
|
||||||
|
try:
|
||||||
|
c = exportdb._conn.cursor()
|
||||||
|
results = c.execute(sql)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[red]Error: {e}[/red]")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
for row in results:
|
||||||
|
print(row)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def _query_options_from_kwargs(**kwargs) -> QueryOptions:
|
def _query_options_from_kwargs(**kwargs) -> QueryOptions:
|
||||||
"""Validate query options and create a QueryOptions instance"""
|
"""Validate query options and create a QueryOptions instance"""
|
||||||
|
|||||||
Reference in New Issue
Block a user