-c / --column option

This commit is contained in:
Simon Willison 2020-12-11 21:48:13 -08:00
commit ef219d6b4d

View file

@ -1361,11 +1361,13 @@ def insert_files(
required=True, required=True,
) )
@click.argument("tables", nargs=-1) @click.argument("tables", nargs=-1)
@click.option("-c", "--column", "columns", type=str, multiple=True, help="Specific columns to analyze")
@click.option("--save", is_flag=True, help="Save results to _analyze_tables table") @click.option("--save", is_flag=True, help="Save results to _analyze_tables table")
@load_extension_option @load_extension_option
def analyze_tables( def analyze_tables(
path, path,
tables, tables,
columns,
save, save,
load_extension, load_extension,
): ):
@ -1379,7 +1381,8 @@ def analyze_tables(
for table in tables: for table in tables:
table_counts[table] = db[table].count table_counts[table] = db[table].count
for column in db[table].columns: for column in db[table].columns:
todo.append((table, column.name)) if (not columns or column.name in columns):
todo.append((table, column.name))
# Now we now how many we need to do # Now we now how many we need to do
for i, (table, column) in enumerate(todo): for i, (table, column) in enumerate(todo):
column_details = db[table].analyze_column(column, total_rows=table_counts[table]) column_details = db[table].analyze_column(column, total_rows=table_counts[table])