From c8ee6797999af954c32e96ac3799a19002f4f0fe Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 21 Feb 2022 16:06:16 -0800 Subject: [PATCH] Added --sql command to exportdb --- osxphotos/cli.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/osxphotos/cli.py b/osxphotos/cli.py index 7d4103f1..0b9b99a1 100644 --- a/osxphotos/cli.py +++ b/osxphotos/cli.py @@ -4808,6 +4808,11 @@ def run(python_file): is_flag=True, 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( "--export-dir", help="Optional path to export directory (if not parent of export database).", @@ -4830,6 +4835,7 @@ def exportdb( save_config, info, migrate, + sql, export_dir, verbose, dry_run, @@ -4857,6 +4863,7 @@ def exportdb( bool(save_config), bool(info), migrate, + bool(sql), ] if sum(sub_commands) > 1: print(f"[red]Only a single sub-command may be specified at a time[/red]") @@ -4975,6 +4982,19 @@ def exportdb( ) 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: """Validate query options and create a QueryOptions instance"""