2018-07-28 06:43:18 -07:00
|
|
|
import click
|
2019-01-24 19:30:47 -08:00
|
|
|
import sqlite_utils
|
2018-07-28 06:43:18 -07:00
|
|
|
|
|
|
|
|
|
2019-01-24 19:30:47 -08:00
|
|
|
@click.group()
|
|
|
|
|
@click.version_option()
|
|
|
|
|
def cli():
|
|
|
|
|
"Commands for interacting with a SQLite database"
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
|
@click.argument(
|
|
|
|
|
"path",
|
|
|
|
|
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
|
|
|
|
|
required=True,
|
|
|
|
|
)
|
2019-01-24 19:57:04 -08:00
|
|
|
@click.option(
|
|
|
|
|
"--fts4", help="Just show FTS4 enabled tables", default=False, is_flag=True
|
|
|
|
|
)
|
|
|
|
|
@click.option(
|
|
|
|
|
"--fts5", help="Just show FTS5 enabled tables", default=False, is_flag=True
|
|
|
|
|
)
|
|
|
|
|
def table_names(path, fts4, fts5):
|
2019-01-24 19:30:47 -08:00
|
|
|
"""List the tables in the database"""
|
|
|
|
|
db = sqlite_utils.Database(path)
|
2019-01-24 19:57:04 -08:00
|
|
|
for name in db.table_names(fts4=fts4, fts5=fts5):
|
2019-01-24 19:30:47 -08:00
|
|
|
print(name)
|
2019-01-24 19:39:04 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
|
@click.argument(
|
|
|
|
|
"path",
|
|
|
|
|
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
|
|
|
|
|
required=True,
|
|
|
|
|
)
|
|
|
|
|
def vacuum(path):
|
|
|
|
|
"""Run VACUUM against the database"""
|
|
|
|
|
sqlite_utils.Database(path).vacuum()
|