Sql clojure中的简单数据库存储
这是一个新手问题。我有一个解析网页并返回一系列5个元素的函数。然后我使用println函数查看它是否正常工作Sql clojure中的简单数据库存储,sql,clojure,Sql,Clojure,这是一个新手问题。我有一个解析网页并返回一系列5个元素的函数。然后我使用println函数查看它是否正常工作 ... (defn select-first-index-page-elements [source element n] ((get-parsing-logic source "parsing-logic-index-page" element "final-touch-fn") (nth (html/select
...
(defn select-first-index-page-elements [source element n]
((get-parsing-logic source "parsing-logic-index-page" element "final-touch-fn")
(nth
(html/select
(fetch-first-page source)
(get-parsing-logic source "parsing-logic-index-page" element "first-touch"))
n)))
(defn parsing-source [source]
(loop [n 0]
(when (< n (count-first-index-page-elements source "title"))
(println ; the group of elements:
(select-first-index-page-elements source "date" n)
" - "
(select-first-index-page-elements source "title" n)
" - "
(select-first-index-page-elements source "url" n)
"\n")
(recur (inc n)))))))
(parsing-source "events-directory-website")
现在,我如何将这些元素存储到数据库中,而不是println函数?如果给定的一组元素已经在数据库中,我怎么能不存储它呢?
我如何才能只打印解析函数找到的新元素组?您可能需要签出 使用sql korma: 如何将这些元素存储到数据库中
(insert my-elements
(values [{:elements ("a" "b" "c")}]))
如果给定的一组元素已经在数据库中,我怎么能不存储它呢
;; using some elements youre looking for
(if-not [is-in-db (select my-elements
(where {:elements the-elements-youre-looking-for}))]
(insert my-elements
(values [{:elements the-elements-youre-looking-for}])))
我如何才能只打印解析函数找到的新元素组?
您可以使用“选择…”解决此问题。。。请输入上述答案
希望这能有所帮助。我得到CannotAcquireResourceException资源池无法从其主要工厂或来源获取资源。com.mchange.v2.resourcepool.BasicResourcePool.java:1319,而不是println。。我放:让[next url select first index page elements source url n]如果不是[db select events where{:url next url}]让[next date select first index page elements source date n next title select first index page elements source title n]插入事件值[{:date next date:title:url next url}]可能签出。确保SQL正在运行,确保您已经在代码中的某个地方声明了db,如。此外,db声明的最简单示例可能位于生成查询的示例下:where defdb被使用。