Found this useful while working on #33 - I should turn it into a documented feature:
+@click.option(
+ "--trace-file",
+ type=click.File("w"),
+ help="Store executed SQL in this file",
+)
@click.option(
"--silent",
is_flag=True,
@@ -145,6 +150,7 @@ def file(
ignore_duplicate_ids,
wal,
debug,
+ trace_file,
silent,
):
"Analyze the history of a specific file and write it to SQLite"
@@ -159,7 +165,15 @@ def file(
"Cannot use --start-at and --start-after at the same time"
)
- db = sqlite_utils.Database(database)
+ if trace_file:
+ db = sqlite_utils.Database(
+ database,
+ tracer=lambda sql, params: trace_file.write(
+ "{} - {}\n".format(sql, params)
+ ),
+ )
+ else:
+ db = sqlite_utils.Database(database)
if wal:
db.enable_wal()
Found this useful while working on #33 - I should turn it into a documented feature: