Skip to content

Commit 535a5ea

Browse files
committed
Documentation and tests for table.drop() method
1 parent 9cb0452 commit 535a5ea

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

docs/python-api.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,17 @@ If you want to ensure that every foreign key column in your database has a corre
567567
568568
db.index_foreign_keys()
569569
570+
.. _python_api_drop:
571+
572+
Dropping a table
573+
================
574+
575+
You can drop a table by using the ``.drop()`` method:
576+
577+
.. code-block:: python
578+
579+
db["my_table"].drop()
580+
570581
.. _python_api_hash:
571582
572583
Setting an ID based on the hash of the row contents

sqlite_utils/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def add_column(
621621
return self
622622

623623
def drop(self):
624-
return self.db.conn.execute("DROP TABLE {}".format(self.name))
624+
self.db.conn.execute("DROP TABLE {}".format(self.name))
625625

626626
def guess_foreign_table(self, column):
627627
column = column.lower()

tests/test_create.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,3 +775,10 @@ def test_cannot_provide_both_filename_and_memory():
775775
def test_creates_id_column(fresh_db):
776776
last_pk = fresh_db.table("cats", pk="id").insert({"name": "barry"}).last_pk
777777
assert [{"name": "barry", "id": last_pk}] == list(fresh_db["cats"].rows)
778+
779+
780+
def test_drop(fresh_db):
781+
fresh_db["t"].insert({"foo": 1})
782+
assert ["t"] == fresh_db.table_names()
783+
assert None is fresh_db["t"].drop()
784+
assert [] == fresh_db.table_names()

0 commit comments

Comments
 (0)