Add the get-articles to read all articles.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
(ns blog.db
|
||||
(:require ["pg" :refer [Client]]
|
||||
[cljs.core.async :refer [go, take!, put!, >!, chan]]
|
||||
[cljs.core.async.interop :refer-macros [<p!]]
|
||||
[blog.env :as env]))
|
||||
|
||||
(defn create-client
|
||||
@@ -18,3 +20,14 @@
|
||||
[client]
|
||||
(. client query "CREATE TABLE IF NOT EXISTS articles (id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, content TEXT NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"))
|
||||
|
||||
(defn get-articles
|
||||
"Reads all articles and returns via channel. It gets and returns the same channel."
|
||||
[client channel]
|
||||
(go
|
||||
(try
|
||||
(let [res (<p! (. client query "select * from articles"))]
|
||||
(>! channel (.-rows res)))
|
||||
(catch js/Error err (js/console.log (ex-cause err))))
|
||||
)
|
||||
channel)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user