sqlite-utils analyze command, refs #379

This commit is contained in:
Simon Willison 2022-01-10 17:24:17 -08:00
commit e0ef9288fe
4 changed files with 76 additions and 1 deletions

View file

@ -304,6 +304,26 @@ def rebuild_fts(path, tables, load_extension):
db[table].rebuild_fts()
@cli.command()
@click.argument(
"path",
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
required=True,
)
@click.argument("names", nargs=-1)
def analyze(path, names):
"""Run ANALYZE against the whole database, or against specific named indexes and tables"""
db = sqlite_utils.Database(path)
try:
if names:
for name in names:
db.analyze(name)
else:
db.analyze()
except sqlite3.OperationalError as e:
raise click.ClickException(e)
@cli.command()
@click.argument(
"path",