From 44face929d3e1e4a964dd4f948acf34cfd5e3c55 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 18 Mar 2026 19:08:15 -0700 Subject: feat: view game by idx rng --- db.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'db.py') diff --git a/db.py b/db.py index 5116708..8e01b82 100644 --- a/db.py +++ b/db.py @@ -119,6 +119,25 @@ def remove_item(category: str, name: str) -> str | None: return actual_name +def count_items(category: str) -> int: + with _get_conn() as conn: + row = conn.execute( + "SELECT COUNT(*) AS cnt FROM items WHERE category = ?", (category,) + ).fetchone() + return row["cnt"] + + +def get_item_by_index(category: str, index: int) -> sqlite3.Row | None: + with _get_conn() as conn: + rows = conn.execute( + "SELECT name, note, added_by FROM items WHERE category = ? ORDER BY id ASC", + (category,), + ).fetchall() + if not rows or index < 1 or index > len(rows): + return None + return rows[index - 1] + + def find_item(category: str, keyword: str = "") -> sqlite3.Row | None: """Return a random item from the category, optionally filtered by keyword in note.""" keyword = keyword.strip().lower() -- cgit v1.2.3