Add function to insert a new article.
This commit is contained in:
@@ -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 (<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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user