本文整理匯總了Golang中menteslibres/net/gosexy/db.Result.Next方法的典型用法代碼示例。如果您正苦於以下問題:Golang Result.Next方法的具體用法?Golang Result.Next怎麽用?Golang Result.Next使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類menteslibres/net/gosexy/db.Result
的用法示例。
在下文中一共展示了Result.Next方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestFind
//.........這裏部分代碼省略.........
}
err = res.All(&dst)
if err != nil {
t.Fatalf(err.Error())
}
if len(dst) != 1 {
t.Fatalf("Could not find a recently appended item.")
}
if dst[0]["name"] != "José" {
t.Fatalf("Could not find a recently appended item.")
}
// Fetch into struct slice.
dst2 := []struct{ Name string }{}
res, err = people.Query(db.Cond{"name": "José"})
if err != nil {
t.Fatalf(err.Error())
}
err = res.All(&dst2)
if err != nil {
t.Fatalf(err.Error())
}
if len(dst2) != 1 {
t.Fatalf("Could not find a recently appended item.")
}
if dst2[0].Name != "José" {
t.Fatalf("Could not find a recently appended item.")
}
// Fetch into map.
dst3 := map[string]interface{}{}
res, err = people.Query(db.Cond{"name": "José"})
if err != nil {
t.Fatalf(err.Error())
}
err = res.One(&dst3)
if err != nil {
t.Fatalf(err.Error())
}
// Fetch into struct.
dst4 := struct{ Name string }{}
res, err = people.Query(db.Cond{"name": "José"})
if err != nil {
t.Fatalf(err.Error())
}
err = res.One(&dst4)
if err != nil {
t.Fatalf(err.Error())
}
if dst4.Name != "José" {
t.Fatalf("Could not find a recently appended item.")
}
// Makes a query and stores the result
res, err = people.Query(nil)
if err != nil {
t.Fatalf(err.Error())
}
dst5 := struct{ Name string }{}
found := false
for {
err = res.Next(&dst5)
if err != nil {
break
}
if dst5.Name == "José" {
found = true
}
}
res.Close()
if found == false {
t.Fatalf("José was not found.")
}
}
示例2: TestFind
//.........這裏部分代碼省略.........
t.Fatalf("Could not find a recently appended item.")
}
if dst[0]["name"] != "José" {
t.Fatalf("Could not find a recently appended item.")
}
// Fetch into struct slice.
dst2 := []struct {
foo string
PersonName string `field:"name"`
none string
}{}
res, err = people.Query(db.Cond{"name": "José"})
if err != nil {
t.Fatalf(err.Error())
}
err = res.All(&dst2)
if err != nil {
t.Fatalf(err.Error())
}
if len(dst2) != 1 {
t.Fatalf("Could not find a recently appended item.")
}
if dst2[0].PersonName != "José" {
t.Fatalf("Could not find a recently appended item.")
}
// Fetch into map.
dst3 := map[string]interface{}{}
res, err = people.Query(db.Cond{"name": "José"})
if err != nil {
t.Fatalf(err.Error())
}
err = res.One(&dst3)
if err != nil {
t.Fatalf(err.Error())
}
// Fetch into struct.
dst4 := struct{ Name string }{}
res, err = people.Query(db.Cond{"name": "José"})
if err != nil {
t.Fatalf(err.Error())
}
err = res.One(&dst4)
if err != nil {
t.Fatalf(err.Error())
}
if dst4.Name != "José" {
t.Fatalf("Could not find a recently appended item.")
}
// Makes a query and stores the result
res, err = people.Query(nil)
if err != nil {
t.Fatalf(err.Error())
}
dst5 := struct {
PersonName string `field:"name"`
}{}
found := false
for {
err = res.Next(&dst5)
if err == nil {
if dst5.PersonName == "José" {
found = true
}
} else if err == db.ErrNoMoreRows {
break
} else {
t.Fatalf(err.Error())
}
}
res.Close()
if found == false {
t.Fatalf("José was not found.")
}
}