我一直在研究这个问题几个小时,而且我还没有与Neo4j的社区Golang驱动程序运气。如何在Go中的Neo4j数据库上运行Cypher查询?
我试图运行“movies-go-cq”和“neoism”示例。 movies-go-cq示例不适用于我,it crashes when localhost:8080 is loaded in the browser。
Cypher在我的Neo4j数据库上使用neoism查询只返回空白/空白数据。但是,当我在localhost:7474的Neo4j浏览器中运行相同的查询时,将返回预期的数据。
这里是Go代码我与neoism运行:
package main
import (
"fmt"
"github.com/jmcvetta/neoism"
)
func main() {
// Reference: https://godoc.org/github.com/jmcvetta/neoism
// Connect to the Neo4j server
db, _ := neoism.Connect("http://localhost:7474/db/data")
// Issue a query
res1 := []struct {
A string `json:"path1"` // `json` tag matches column name in query
B string `json:"path2"`
}{}
cq1 := neoism.CypherQuery{
// Use backticks for long statements - Cypher is whitespace indifferent
Statement: `
MATCH path1 = shortestPath((plant:Plant {Term: "Vaccinium corymbosum"})-[*..5]-(gene:Gene {Description: "adenylate cyclase activating polypeptide 1"}))
MATCH path2 = shortestPath((gene)-[*..5]-(disease:Medical_Heading {Term: "Alzheimer Disease"}))
RETURN path1, path2
`,
Result: &res1,
}
db.Cypher(&cq1)
r := res1[0]
fmt.Println(r.A, r.B)
}
我正在考虑写在Go使用的Neo4j的HTTP REST的API,如果我不能得到现有转到驱动程序才能正常工作,我自己的API包装;我是Golang的新手,我会很感激任何有关调试Go代码的建议或在Golang中使用Neo4j的技巧。感谢您的时间。
[db.Cypher](https://godoc.org/github.com/jmcvetta/neoism#Database.Cypher)返回错误。你能捕捉到('err:= db.Cypher(&cq1)')并用'err'的值更新你的问题吗? – algrebe