Add functions to get an article or articles with the brief content.
This commit is contained in:
+34
-2
@@ -26,7 +26,21 @@
|
||||
[client channel]
|
||||
(go
|
||||
(try
|
||||
(let [res (<p! (. client query "select * from articles"))]
|
||||
(let [res (<p! (. client query "select id, title, content, created from articles"))]
|
||||
(>! 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 (<p! (. client query
|
||||
(str "select id, title,"
|
||||
"substr(content, 0, 60) content,"
|
||||
"length(content) content_length,"
|
||||
"created from articles")))]
|
||||
(>! channel (.-rows res)))
|
||||
(catch js/Error err (js/console.log (ex-cause err)))))
|
||||
channel)
|
||||
@@ -37,7 +51,25 @@
|
||||
(go
|
||||
(try
|
||||
(let [res (<p! (.query client
|
||||
"select * from articles where id=$1"
|
||||
"select id, title, content, created from articles where id=$1"
|
||||
(clj->js [id])))]
|
||||
(>! channel (-> (.-rows res)
|
||||
(js->clj :keywordize-keys true)
|
||||
(first))))
|
||||
(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 (<p! (.query client
|
||||
(str "select id, title,"
|
||||
"substr(content, 0, 60) content,"
|
||||
"length(content) content_length,"
|
||||
"created from articles"
|
||||
"where id=$1")
|
||||
(clj->js [id])))]
|
||||
(>! channel (-> (.-rows res)
|
||||
(js->clj :keywordize-keys true)
|
||||
|
||||
Reference in New Issue
Block a user