Separate View and Table classes

Both of these subclass a common Queryable class.

Also updated documentation to cover the new View class.

And added view.drop() method.
This commit is contained in:
Simon Willison 2019-08-21 13:12:12 +03:00
commit 4441d6d838
4 changed files with 101 additions and 68 deletions

View file

@ -782,3 +782,10 @@ def test_drop(fresh_db):
assert ["t"] == fresh_db.table_names()
assert None is fresh_db["t"].drop()
assert [] == fresh_db.table_names()
def test_drop_view(fresh_db):
fresh_db.create_view("foo_view", "select 1")
assert ["foo_view"] == fresh_db.view_names()
assert None is fresh_db["foo_view"].drop()
assert [] == fresh_db.view_names()

View file

@ -1,4 +1,4 @@
from sqlite_utils.db import Index
from sqlite_utils.db import Index, View
import pytest
@ -45,10 +45,10 @@ def test_views(fresh_db):
fresh_db.create_view("foo_view", "select 1")
assert 1 == len(fresh_db.views)
view = fresh_db.views[0]
assert view.is_view
assert view.exists
assert isinstance(view, View)
assert "foo_view" == view.name
assert "<View foo_view (1)>" == repr(view)
assert {"1": str} == view.columns_dict
def test_count(existing_db):