我在我的一個應用程式中使用 neo4j。
如果找到值,則運行查詢后,result.Next()回傳一個bool
var matches []int
fmt.Println(result.Next(), "<== result NEXT ???") // ?? this prints true
if result.Next() {
// ?? for some reason this block won't run!
fmt.Println("Assigning the values to the var")
matches = result.Record().Values()[0].([]int)
fmt.Println("Matches found", matches)
}
我非常感謝您的幫助,堅持了幾個小時
uj5u.com熱心網友回復:
呼叫result.Next()繼續到下一行。如果你呼叫它兩次,你會跳過一行。result.Next()不是冪等的!如果你只有一個結果,呼叫result.Next(),第二個呼叫將永遠不會回傳true。
如果您需要result.Next()在多個位置檢查結果,請將其存盤在變數中:
var matches []int
hasNext := result.Next()
fmt.Println(hasNext, "<== result NEXT ???")
if hasNext {
fmt.Println("Assigning the values to the var")
matches = result.Record().Values()[0].([]int)
fmt.Println("Matches found", matches)
}
參考官方檔案:消費結果:
for result.Next() {
list = append(list, result.Record().Values[0].(string))
}
如您所見,只需呼叫result.Next().
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/414532.html
標籤:
