mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-10 10:34:10 +02:00
--ignore for sqlite-utils drop-table and drop-view, closes #237
This commit is contained in:
parent
c236894caa
commit
bba6e241be
3 changed files with 36 additions and 9 deletions
|
|
@ -736,6 +736,8 @@ You can drop a table using the ``drop-table`` command::
|
||||||
|
|
||||||
$ sqlite-utils drop-table mydb.db mytable
|
$ sqlite-utils drop-table mydb.db mytable
|
||||||
|
|
||||||
|
Use ``--ignore`` to ignore the error if the table does not exist.
|
||||||
|
|
||||||
.. _cli_transform_table:
|
.. _cli_transform_table:
|
||||||
|
|
||||||
Transforming tables
|
Transforming tables
|
||||||
|
|
@ -922,6 +924,8 @@ You can drop a view using the ``drop-view`` command::
|
||||||
|
|
||||||
$ sqlite-utils drop-view myview
|
$ sqlite-utils drop-view myview
|
||||||
|
|
||||||
|
Use ``--ignore`` to ignore the error if the view does not exist.
|
||||||
|
|
||||||
.. _cli_add_column:
|
.. _cli_add_column:
|
||||||
|
|
||||||
Adding columns
|
Adding columns
|
||||||
|
|
|
||||||
|
|
@ -946,14 +946,15 @@ def create_table(
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
@click.argument("table")
|
@click.argument("table")
|
||||||
|
@click.option("--ignore", is_flag=True)
|
||||||
@load_extension_option
|
@load_extension_option
|
||||||
def drop_table(path, table, load_extension):
|
def drop_table(path, table, ignore, load_extension):
|
||||||
"Drop the specified table"
|
"Drop the specified table"
|
||||||
db = sqlite_utils.Database(path)
|
db = sqlite_utils.Database(path)
|
||||||
_load_extensions(db, load_extension)
|
_load_extensions(db, load_extension)
|
||||||
if table in db.table_names():
|
try:
|
||||||
db[table].drop()
|
db[table].drop(ignore=ignore)
|
||||||
else:
|
except sqlite3.OperationalError:
|
||||||
raise click.ClickException('Table "{}" does not exist'.format(table))
|
raise click.ClickException('Table "{}" does not exist'.format(table))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1002,14 +1003,15 @@ def create_view(path, view, select, ignore, replace, load_extension):
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
@click.argument("view")
|
@click.argument("view")
|
||||||
|
@click.option("--ignore", is_flag=True)
|
||||||
@load_extension_option
|
@load_extension_option
|
||||||
def drop_view(path, view, load_extension):
|
def drop_view(path, view, ignore, load_extension):
|
||||||
"Drop the specified view"
|
"Drop the specified view"
|
||||||
db = sqlite_utils.Database(path)
|
db = sqlite_utils.Database(path)
|
||||||
_load_extensions(db, load_extension)
|
_load_extensions(db, load_extension)
|
||||||
if view in db.view_names():
|
try:
|
||||||
db[view].drop()
|
db[view].drop(ignore=ignore)
|
||||||
else:
|
except sqlite3.OperationalError:
|
||||||
raise click.ClickException('View "{}" does not exist'.format(view))
|
raise click.ClickException('View "{}" does not exist'.format(view))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1397,7 +1397,17 @@ def test_drop_table_error():
|
||||||
)
|
)
|
||||||
assert 1 == result.exit_code
|
assert 1 == result.exit_code
|
||||||
assert 'Error: Table "t2" does not exist' == result.output.strip()
|
assert 'Error: Table "t2" does not exist' == result.output.strip()
|
||||||
|
# Using --ignore supresses that error
|
||||||
|
result = runner.invoke(
|
||||||
|
cli.cli,
|
||||||
|
[
|
||||||
|
"drop-table",
|
||||||
|
"test.db",
|
||||||
|
"t2",
|
||||||
|
"--ignore"
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert 0 == result.exit_code
|
||||||
|
|
||||||
def test_drop_view():
|
def test_drop_view():
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
|
|
@ -1432,6 +1442,17 @@ def test_drop_view_error():
|
||||||
)
|
)
|
||||||
assert 1 == result.exit_code
|
assert 1 == result.exit_code
|
||||||
assert 'Error: View "t2" does not exist' == result.output.strip()
|
assert 'Error: View "t2" does not exist' == result.output.strip()
|
||||||
|
# Using --ignore supresses that error
|
||||||
|
result = runner.invoke(
|
||||||
|
cli.cli,
|
||||||
|
[
|
||||||
|
"drop-view",
|
||||||
|
"test.db",
|
||||||
|
"t2",
|
||||||
|
"--ignore"
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert 0 == result.exit_code
|
||||||
|
|
||||||
|
|
||||||
def test_enable_wal():
|
def test_enable_wal():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue