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

@ -129,7 +129,7 @@ def test_uses_counts_after_enable_counts(counts_db_path):
db = Database(counts_db_path)
logged = []
with db.tracer(lambda sql, parameters: logged.append((sql, parameters))):
assert db["foo"].count == 1
assert db.table("foo").count == 1
assert logged == [
("select name from sqlite_master where type = 'view'", None),
("select count(*) from [foo]", []),
@ -138,7 +138,7 @@ def test_uses_counts_after_enable_counts(counts_db_path):
assert not db.use_counts_table
db.enable_counts()
assert db.use_counts_table
assert db["foo"].count == 1
assert db.table("foo").count == 1
assert logged == [
(
"CREATE TABLE IF NOT EXISTS [_counts](\n [table] TEXT PRIMARY KEY,\n count INTEGER DEFAULT 0\n);",