This commit is contained in:
Miguel Jacq 2025-11-14 13:18:58 +11:00
parent df7ae0b42d
commit 5e283ecf17
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
8 changed files with 294 additions and 21 deletions

View file

@ -25,6 +25,7 @@ _TAG_COLORS = [
"#E0BAFF", # soft purple
]
@dataclass
class DBConfig:
path: Path
@ -198,7 +199,6 @@ class DBManager:
).fetchall()
return [(r[0], r[1]) for r in rows]
def dates_with_content(self) -> list[str]:
"""
Find all entries and return the dates of them.
@ -560,6 +560,28 @@ class DBManager:
cur.execute("DELETE FROM page_tags WHERE tag_id=?;", (tag_id,))
cur.execute("DELETE FROM tags WHERE id=?;", (tag_id,))
def get_pages_for_tag(self, tag_name: str) -> list[Entry]:
"""
Return (date, content) for pages that have the given tag.
"""
cur = self.conn.cursor()
rows = cur.execute(
"""
SELECT p.date, v.content
FROM pages AS p
JOIN versions AS v
ON v.id = p.current_version_id
JOIN page_tags pt
ON pt.page_date = p.date
JOIN tags t
ON t.id = pt.tag_id
WHERE LOWER(t.name) = LOWER(?)
ORDER BY p.date DESC;
""",
(tag_name,),
).fetchall()
return [(r[0], r[1]) for r in rows]
def close(self) -> None:
if self.conn is not None:
self.conn.close()