[英]clojure.core/for with Cypher ExecutionResult
(defn cypher
[query]
(let [result (-> *cypher* (.execute query))]
(for [row result
column (.entrySet row)]
{(keyword (.getKey column))
(Neo4jVertex. (.getValue column) *g*)})))
repl=> (cypher "start n=node:people('*:*') return n")
{:n #<Neo4jVertex v[1]>}
This query returns two results, yet I'm only able to ever see one using clojure.core/for
. 该查询返回两个结果,但是我只能使用clojure.core/for
查看一个结果。 How should I be going about this? 我应该怎么做?
The Neo4j docs have this example (which is what I'm trying to emulate): Neo4j文档具有以下示例(这是我要模拟的示例):
for ( Map<String, Object> row : result )
{
for ( Entry<String, Object> column : row.entrySet() )
{
rows += column.getKey() + ": " + column.getValue() + "; ";
}
rows += "\n";
}
I think you need clojure.core/doseq
( docs ) instead. 我认为您需要使用clojure.core/doseq
( docs )。
user=> (doseq [row [1 2 3]]
#_=> [result [4 5 6]]
#_=> (println (str {:row row :result result}))))
{:row 1, :result 4}
{:row 1, :result 5}
{:row 1, :result 6}
{:row 2, :result 4}
{:row 2, :result 5}
{:row 2, :result 6}
{:row 3, :result 4}
{:row 3, :result 5}
{:row 3, :result 6}
So, adapted to your example, something like the following might work: 因此,根据您的示例,可能会执行以下操作:
; ...
(doseq [row result]
[column (.entrySet row)]
(println (str {(keyword (.getKey column)) (Neo4jVertex. (.getValue column) *g*)}))))
; ...
Note that doseq
returns nil
; 注意, doseq
返回nil
; you'll have to call something with side effects like println
in the body of the doseq
form. 您必须在doseq
表单的主体中调用诸如println
之类的doseq
。
It looks like clojure.core/for
does list comprehension, so something like the following actually returns a list: 看起来clojure.core/for
确实具有列表理解功能,因此类似下面的内容实际上返回一个列表:
user=> (for [row [1 2 3]
#_=> result [4 5 6]]
#_=> {:row row :result result})
({:row 1, :result 4} {:row 1, :result 5} {:row 1, :result 6} {:row 2, :result 4} {:row 2, :result 5} {:row 2, :result 6} {:row 3, :result 4} {:row 3, :result 5} {:row 3, :result 6})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.