db.table() only returns tables, added db.view()

* db.table() only returns tables, added db.view(), closes #657
* Massive documentation update for db.table()

Refs #656
This commit is contained in:
Simon Willison 2025-05-08 23:19:36 -07:00 committed by GitHub
commit 094b010fd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 276 additions and 229 deletions

View file

@ -8,6 +8,8 @@ from sqlite_utils.db import (
ForeignKey,
Table,
View,
NoTable,
NoView,
)
from sqlite_utils.utils import hash_record, sqlite3
import collections
@ -1367,3 +1369,14 @@ def test_create_strict(fresh_db, strict):
table = fresh_db["t"]
table.create({"id": int}, strict=strict)
assert table.strict == strict or not fresh_db.supports_strict
def test_bad_table_and_view_exceptions(fresh_db):
fresh_db.table("t").insert({"id": 1}, pk="id")
fresh_db.create_view("v", "select * from t")
with pytest.raises(NoTable) as ex:
fresh_db.table("v")
assert ex.value.args[0] == "Table v is actually a view"
with pytest.raises(NoView) as ex2:
fresh_db.view("t")
assert ex2.value.args[0] == "View t does not exist"