From 72b9e604cad8b023f596531a6772e6f4aa06a1ea Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 10 Apr 2024 21:41:46 +0300 Subject: [PATCH] Add functions to get an article or articles with the brief content. --- src/main/blog/db.cljs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/blog/db.cljs b/src/main/blog/db.cljs index ed98492..48e28e6 100644 --- a/src/main/blog/db.cljs +++ b/src/main/blog/db.cljs @@ -26,7 +26,21 @@ [client channel] (go (try - (let [res (! channel (.-rows res))) + (catch js/Error err (js/console.log (ex-cause err))))) + channel) + +(defn get-articles-briefly + "Reads all articles and returns via channel. It gets and returns the same channel. The content will be brief (<=60 characters)." + [client channel] + (go + (try + (let [res (! channel (.-rows res))) (catch js/Error err (js/console.log (ex-cause err))))) channel) @@ -37,7 +51,7 @@ (go (try (let [res (js [id])))] (>! channel (-> (.-rows res) (js->clj :keywordize-keys true) @@ -45,6 +59,24 @@ (catch js/Error err (js/console.log (ex-cause err))))) channel) +(defn get-article-briefly + "Reads an article with the id and returns via channel. It gets and returns the same channel. Empty collection if not found. The content will be brief (<=60 characters)." + [client id channel] + (go + (try + (let [res (js [id])))] + (>! channel (-> (.-rows res) + (js->clj :keywordize-keys true) + (first)))) + (catch js/Error err (js/console.log (ex-cause err))))) + channel) + (defn insert-article "Insert an article and return the id via channel. It gets and returns the same channel." [client title content channel]