mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 09:54:31 +02:00
sqlite-utils create-index command, closes #14
This commit is contained in:
parent
7784b924a1
commit
8a5d0d80c3
3 changed files with 95 additions and 0 deletions
|
|
@ -134,6 +134,30 @@ def optimize(path, no_vacuum):
|
|||
db.vacuum()
|
||||
|
||||
|
||||
@cli.command(name="create-index")
|
||||
@click.argument(
|
||||
"path",
|
||||
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
|
||||
required=True,
|
||||
)
|
||||
@click.argument("table")
|
||||
@click.argument("column", nargs=-1, required=True)
|
||||
@click.option("--name", help="Explicit name for the new index")
|
||||
@click.option("--unique", help="Make this a unique index", default=False, is_flag=True)
|
||||
@click.option(
|
||||
"--if-not-exists",
|
||||
help="Ignore if index already exists",
|
||||
default=False,
|
||||
is_flag=True,
|
||||
)
|
||||
def create_index(path, table, column, name, unique, if_not_exists):
|
||||
"Add an index to the specified table covering the specified columns"
|
||||
db = sqlite_utils.Database(path)
|
||||
db[table].create_index(
|
||||
column, index_name=name, unique=unique, if_not_exists=if_not_exists
|
||||
)
|
||||
|
||||
|
||||
@cli.command(name="enable-fts")
|
||||
@click.argument(
|
||||
"path",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue