From 62c3ddf5b722a5e412855b097f7f12a600bb5b78 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 22 Jan 2026 22:20:15 +0100 Subject: words: add the 'dup' subcommand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an easy way to create alternatives from existing words. Signed-off-by: Miquel Sabaté Solà --- lib/mihi/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs index 9d65b1c..e26f220 100644 --- a/lib/mihi/src/lib.rs +++ b/lib/mihi/src/lib.rs @@ -299,6 +299,21 @@ impl TryFrom for RelationKind { } } +/// Add a row in `word_relations` so the words identified by `one_id` and +/// `other_id` are set to have the `kind` relationship. +pub fn add_word_relationship(one_id: i64, other_id: i64, kind: RelationKind) -> Result<(), String> { + let conn = get_connection()?; + + match conn.execute( + "INSERT INTO word_relations (source_id, destination_id, kind, updated_at, created_at) \ + VALUES (?1, ?2, ?3, datetime('now'), datetime('now'))", + params![one_id, other_id, kind as isize], + ) { + Ok(_) => Ok(()), + Err(e) => Err(e.to_string()), + } +} + /// Join by enunciate the given words. pub fn joint_related_words(related: &[Word]) -> String { related -- cgit v1.2.3