Add function to insert a new article.

main
KKlochko 1 year ago
parent 46f017d716
commit 2b1ea5d806

@ -45,3 +45,18 @@
(catch js/Error err (js/console.log (ex-cause err))))) (catch js/Error err (js/console.log (ex-cause err)))))
channel) 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 (<p! (.query client
"insert into articles(title, content) values($1, $2) returning id;"
(clj->js [title content])))]
(>! channel (-> (.-rows res)
(js->clj :keywordize-keys true)
(first)
(:id))))
(catch js/Error err (js/console.log (ex-cause err)))))
channel)

Loading…
Cancel
Save