mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-25 10:24:32 +02:00
sqlite-utils optimize command, .optimize() and .detect_fts() table methods
This commit is contained in:
parent
015bd2a840
commit
0a8194e730
7 changed files with 146 additions and 4 deletions
|
|
@ -37,3 +37,21 @@ def table_names(path, fts4, fts5):
|
|||
def vacuum(path):
|
||||
"""Run VACUUM against the database"""
|
||||
sqlite_utils.Database(path).vacuum()
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument(
|
||||
"path",
|
||||
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
|
||||
required=True,
|
||||
)
|
||||
@click.option("--no-vacuum", help="Don't run VACUUM", default=False, is_flag=True)
|
||||
def optimize(path, no_vacuum):
|
||||
"""Optimize all FTS tables and then run VACUUM - should shrink the database file"""
|
||||
db = sqlite_utils.Database(path)
|
||||
tables = db.table_names(fts4=True) + db.table_names(fts5=True)
|
||||
with db.conn:
|
||||
for table in tables:
|
||||
db[table].optimize()
|
||||
if not no_vacuum:
|
||||
db.vacuum()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue