aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-01-14 22:36:54 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-01-14 22:39:40 +0100
commit0c89256c782f0d1e98e93047fa90ad90b4e003e3 (patch)
tree67165aa26061867ac1c3af278a0d98be40671ace /lib
parent9bc834bcb6e694a0ce065fc8c638c699b62688c5 (diff)
downloadmihi-0c89256c782f0d1e98e93047fa90ad90b4e003e3.tar.gz
mihi-0c89256c782f0d1e98e93047fa90ad90b4e003e3.zip
Touch the 'updated_at' column on exercise success
If the user runs into an exercise and is satisfied with the results, then touch the 'updated_at' column for that exercise. This is relevant because in practice exercises are selected by the lastly updated exercise. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/mihi/src/lib.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs
index 2915368..4d337b9 100644
--- a/lib/mihi/src/lib.rs
+++ b/lib/mihi/src/lib.rs
@@ -856,6 +856,25 @@ pub fn update_exercise(exercise: Exercise) -> Result<(), String> {
}
}
+/// Updates the 'updated_at' column for an exercise.
+pub fn touch_exercise(exercise: Exercise) -> Result<(), String> {
+ if exercise.id == 0 {
+ return Err("invalid exercise to update; seems it has not been created before".to_string());
+ }
+
+ let conn = get_connection()?;
+
+ match conn.execute(
+ "UPDATE exercises \
+ SET updated_at = datetime('now') \
+ WHERE id = ?1",
+ params![exercise.id],
+ ) {
+ Ok(_) => Ok(()),
+ Err(e) => Err(format!("could not update '{}': {}", exercise.title, e)),
+ }
+}
+
/// Delete an exercise from the database.
pub fn delete_exercise(title: &str) -> Result<(), String> {
let conn = get_connection()?;