table.count_where() method, closes #305

This commit is contained in:
Simon Willison 2021-08-01 22:05:03 -07:00
commit 4823aff4c3
4 changed files with 45 additions and 10 deletions

View file

@ -132,7 +132,7 @@ def test_uses_counts_after_enable_counts(counts_db_path):
assert db["foo"].count == 1
assert logged == [
("select name from sqlite_master where type = 'view'", None),
("select count(*) from [foo]", None),
("select count(*) from [foo]", []),
]
logged.clear()
assert not db.use_counts_table

View file

@ -52,7 +52,14 @@ def test_views(fresh_db):
def test_count(existing_db):
assert 3 == existing_db["foo"].count
assert existing_db["foo"].count == 3
assert existing_db["foo"].count_where() == 3
assert existing_db["foo"].execute_count() == 3
def test_count_where(existing_db):
assert existing_db["foo"].count_where("text != ?", ["two"]) == 2
assert existing_db["foo"].count_where("text != :t", {"t": "two"}) == 2
def test_columns(existing_db):