From 1ad0610f19384916f7a22b3ebae41359a18eade5 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 27 Mar 2024 17:08:41 +0200 Subject: [PATCH] Add a function to get an article by id. --- src/main/blog/db.cljs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/blog/db.cljs b/src/main/blog/db.cljs index c39a6a2..744ae20 100644 --- a/src/main/blog/db.cljs +++ b/src/main/blog/db.cljs @@ -27,7 +27,18 @@ (try (let [res (! channel (.-rows res))) - (catch js/Error err (js/console.log (ex-cause err)))) - ) + (catch js/Error err (js/console.log (ex-cause err))))) + channel) + +(defn get-article + "Reads an article with the id and returns via channel. It gets and returns the same channel. Empty collection if not found." + [client id channel] + (go + (try + (let [res (js [id])))] + (>! channel (.-rows res))) + (catch js/Error err (js/console.log (ex-cause err))))) channel)