From 2b1ea5d80666a7a4bcf8b68211f5ae25875b78d0 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 2 Apr 2024 13:28:27 +0300 Subject: [PATCH] Add function to insert a new article. --- src/main/blog/db.cljs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/blog/db.cljs b/src/main/blog/db.cljs index 941cda3..038a69c 100644 --- a/src/main/blog/db.cljs +++ b/src/main/blog/db.cljs @@ -45,3 +45,18 @@ (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] + (go + (try + (let [res (js [title content])))] + (>! channel (-> (.-rows res) + (js->clj :keywordize-keys true) + (first) + (:id)))) + (catch js/Error err (js/console.log (ex-cause err))))) + channel) +