From 22f19cf9f50ae4ce96b175366602b9a2816332a6 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 19 Jan 2026 21:49:45 +0100 Subject: words: add the poke subcommand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This subcommand allows the user to update the `updated_at` timestamp, which is quite relevant as this timestamp is used when selecting words. Signed-off-by: Miquel Sabaté Solà --- lib/mihi/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib') diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs index d75965d..0c44335 100644 --- a/lib/mihi/src/lib.rs +++ b/lib/mihi/src/lib.rs @@ -646,6 +646,24 @@ pub fn update_word(word: Word) -> Result<(), String> { } } +/// Update the `updated_at` timestamp for any word matching the given +/// `enunciated` string. In theory the given enunciated should identify only a +/// single word, but nothing forbids the caller from updating every word which +/// somehow matches the given string. +pub fn update_timestamp(enunciated: &str) -> Result<(), String> { + let conn = get_connection()?; + + match conn.execute( + "UPDATE words \ + SET updated_at = datetime('now') \ + WHERE enunciated = ?1", + params![enunciated], + ) { + Ok(_) => Ok(()), + Err(e) => Err(format!("could not update '{}': {}", enunciated, e)), + } +} + pub fn select_enunciated(filter: Option) -> Result, String> { let conn = get_connection()?; -- cgit v1.2.3