【发布时间】:2017-07-06 13:43:20
【问题描述】:
我刚开始在Heroku 上使用Clojure,初读this introduction。
现在在弄脏我的手的阶段,我面临着处理循环数据库的问题。
这是有效的:
(for
[s (db/query (env :database-url)
["select * from My_List"])]
; here one can do something with s, for example:
; print out (:field s)
)
但是仅仅按照我的意愿更新循环内的变量是不够的。 阅读该主题后,我了解到 Clojure 有自己的变量处理方式,我需要使用循环模式。
这是我尝试过的:
(loop [a 0 b 1
s (db/query (env :database-url)
["select * from My_List"])]
; here I want to do something with s, for example
; print out (:field s)
; and do the following ... but it does not work!
(if (> (:otherField s) 5)
(:otherField s)
(recur (+ a (:otherField s)) b s))
)
由于在写这篇文章之前我尝试了各种方法,我知道上面的代码可以工作,除了我在数据库方面做错了。
所以我的问题来了:我需要改变什么才能让它工作?
【问题讨论】:
标签: database postgresql heroku clojure heroku-postgres