diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-03-18 19:08:15 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-03-18 19:08:15 -0700 |
| commit | 44face929d3e1e4a964dd4f948acf34cfd5e3c55 (patch) | |
| tree | 3acf0f1d4c25d41a7e246d109a3f641a3536e517 /db.py | |
| parent | 9a4561069ea3a794f1d66d0b2ff04d8d1ff20411 (diff) | |
feat: view game by idx rng
Diffstat (limited to 'db.py')
| -rw-r--r-- | db.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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() |
