aboutsummaryrefslogtreecommitdiffstats
path: root/models.py
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-03-18 15:26:22 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-03-18 15:26:22 +0100
commit7ecba24a3383d4e331c812b0dcd57bc7bf565713 (patch)
tree701940ca20e375cec087ca5dc6e5c450595ad1e0 /models.py
parent81c3cbf634e1e6929317d3ffcd87df6426808417 (diff)
downloadEgoMetrics-7ecba24a3383d4e331c812b0dcd57bc7bf565713.tar.gz
EgoMetrics-7ecba24a3383d4e331c812b0dcd57bc7bf565713.zip
Add body weight logging with diff tracking
Diffstat (limited to 'models.py')
-rw-r--r--models.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/models.py b/models.py
index a844271..6def19e 100644
--- a/models.py
+++ b/models.py
@@ -252,3 +252,33 @@ def save_workout_template_exercises(
),
)
conn.commit()
+
+
+# --- Weight Logs ---
+
+
+def add_weight_log(
+ conn: sqlite3.Connection,
+ date_time: str,
+ weight: float,
+ note: str | None = None,
+) -> int:
+ cur = conn.execute(
+ "INSERT INTO weight_logs (date_time, weight, note) VALUES (?, ?, ?)",
+ (date_time, weight, note),
+ )
+ conn.commit()
+ assert cur.lastrowid is not None
+ return cur.lastrowid
+
+
+def list_weight_logs(conn: sqlite3.Connection, limit: int = 20) -> list[sqlite3.Row]:
+ return conn.execute(
+ "SELECT id, date_time, weight, note FROM weight_logs ORDER BY date_time DESC LIMIT ?",
+ (limit,),
+ ).fetchall()
+
+
+def delete_weight_log(conn: sqlite3.Connection, log_id: int) -> None:
+ conn.execute("DELETE FROM weight_logs WHERE id = ?", (log_id,))
+ conn.commit()