mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
drop-table and drop-view commands, closes #111
This commit is contained in:
parent
396bee9236
commit
4e9cb739c7
3 changed files with 120 additions and 0 deletions
|
|
@ -594,6 +594,22 @@ def create_table(path, table, columns, pk, not_null, default, fk, ignore, replac
|
|||
)
|
||||
|
||||
|
||||
@cli.command(name="drop-table")
|
||||
@click.argument(
|
||||
"path",
|
||||
type=click.Path(file_okay=True, dir_okay=False, allow_dash=False),
|
||||
required=True,
|
||||
)
|
||||
@click.argument("table")
|
||||
def drop_table(path, table):
|
||||
"Drop the specified table"
|
||||
db = sqlite_utils.Database(path)
|
||||
if table in db.table_names():
|
||||
db[table].drop()
|
||||
else:
|
||||
raise click.ClickException('Table "{}" does not exist'.format(table))
|
||||
|
||||
|
||||
@cli.command(name="create-view")
|
||||
@click.argument(
|
||||
"path",
|
||||
|
|
@ -626,6 +642,23 @@ def create_view(path, view, select, ignore, replace):
|
|||
db.create_view(view, select)
|
||||
|
||||
|
||||
@cli.command(name="drop-view")
|
||||
@click.argument(
|
||||
"path",
|
||||
type=click.Path(file_okay=True, dir_okay=False, allow_dash=False),
|
||||
required=True,
|
||||
)
|
||||
@click.argument("view")
|
||||
def drop_view(path, view):
|
||||
"Drop the specified view"
|
||||
db = sqlite_utils.Database(path)
|
||||
if view in db.view_names():
|
||||
db[view].drop()
|
||||
else:
|
||||
raise click.ClickException('View "{}" does not exist'.format(view))
|
||||
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument(
|
||||
"path",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue