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]