I'm learning Clojure and I have a question about the basics.
我正在学习Clojure,我对基础知识有疑问。
How can I make the function to return the "rows" variable:
如何使函数返回“rows”变量:
(defn list-domains []
(sql/with-connection db
(sql/with-query-results rows ["select * from domains"]
rows)))
thanks
1 个解决方案
#1
2
Long time since I've played [FR] with clojure, but as far as I remember, sql/with-query-results
does not return result. It merely evaluate a sub-expression (the last parameter) with the query result as a parameter:
很久以来我用clojure玩了[FR],但据我记忆,sql / with-query-results不会返回结果。它只是用查询结果作为参数来评估子表达式(最后一个参数):
(defn list-domains []
(sql/with-connection db
(sql/with-query-results rows ["select * from domains"]
(do-something-with rows) )))
If you really want to return, you could try to instantiate the sequence by using doall
:
如果你真的想要返回,你可以尝试使用doall实例化序列:
(defn list-domains []
(sql/with-connection db
(sql/with-query-results rows ["select * from domains"]
(doall rows) )))
EDIT: Hum ... well ... as a matter of fact, this is the exact same solution as provided by the documentation for with-query-results
:/
编辑:嗯......好吧......事实上,这是与查询结果文档提供的完全相同的解决方案:/
#1
2
Long time since I've played [FR] with clojure, but as far as I remember, sql/with-query-results
does not return result. It merely evaluate a sub-expression (the last parameter) with the query result as a parameter:
很久以来我用clojure玩了[FR],但据我记忆,sql / with-query-results不会返回结果。它只是用查询结果作为参数来评估子表达式(最后一个参数):
(defn list-domains []
(sql/with-connection db
(sql/with-query-results rows ["select * from domains"]
(do-something-with rows) )))
If you really want to return, you could try to instantiate the sequence by using doall
:
如果你真的想要返回,你可以尝试使用doall实例化序列:
(defn list-domains []
(sql/with-connection db
(sql/with-query-results rows ["select * from domains"]
(doall rows) )))
EDIT: Hum ... well ... as a matter of fact, this is the exact same solution as provided by the documentation for with-query-results
:/
编辑:嗯......好吧......事实上,这是与查询结果文档提供的完全相同的解决方案:/