mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
修正数据库GetOne/One方法
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
// 数据库查询,获取查询字段值
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
// 链式操作,查询字段值
|
||||
|
||||
@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user