修正数据库GetOne/One方法

This commit is contained in:
John
2018-04-18 16:32:54 +08:00
parent c25330eac0
commit 91af060e8a
3 changed files with 13 additions and 3 deletions

View File

@ -108,7 +108,10 @@ func (db *Db) GetOne(query string, args ...interface{}) (Map, error) {
if err != nil {
return nil, err
}
return list[0], nil
if len(list) > 0 {
return list[0], nil
}
return nil, nil
}
// 数据库查询,获取查询字段值

View File

@ -261,7 +261,10 @@ func (op *DbOp) One() (Map, error) {
if err != nil {
return nil, err
}
return list[0], nil
if len(list) > 0 {
return list[0], nil
}
return nil, nil
}
// 链式操作,查询字段值

View File

@ -446,7 +446,7 @@ func main() {
//save()
//batchInsert()
//update1()
update2()
//update2()
//update3()
//linkopSelect1()
//linkopSelect2()
@ -457,4 +457,8 @@ func main() {
//keepPing()
//transaction1()
//transaction2()
m, e := db.Table("user").Fields("uid,name").Where("uid = ?", 4).One()
fmt.Println(e)
fmt.Println(m)
}