mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
修改gdb.Value类型的数据结构为[]byte,并改进ORM的Value方法,返回Value数据类型
This commit is contained in:
@ -36,7 +36,7 @@ type Link interface {
|
||||
// 数据库查询
|
||||
GetAll(q string, args ...interface{}) (Result, error)
|
||||
GetOne(q string, args ...interface{}) (Record, error)
|
||||
GetValue(q string, args ...interface{}) (interface{}, error)
|
||||
GetValue(q string, args ...interface{}) (Value, error)
|
||||
|
||||
// Ping
|
||||
PingMaster() error
|
||||
@ -89,7 +89,7 @@ type Db struct {
|
||||
}
|
||||
|
||||
// 返回数据表记录值
|
||||
type Value string
|
||||
type Value []byte
|
||||
|
||||
// 返回数据表记录Map
|
||||
type Record map[string]Value
|
||||
|
||||
@ -115,7 +115,7 @@ func (db *Db) GetOne(query string, args ...interface{}) (Record, error) {
|
||||
}
|
||||
|
||||
// 数据库查询,获取查询字段值
|
||||
func (db *Db) GetValue(query string, args ...interface{}) (interface{}, error) {
|
||||
func (db *Db) GetValue(query string, args ...interface{}) (Value, error) {
|
||||
one, err := db.GetOne(query, args ...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -276,15 +276,15 @@ func (md *Model) One() (Record, error) {
|
||||
}
|
||||
|
||||
// 链式操作,查询字段值
|
||||
func (md *Model) Value() (interface{}, error) {
|
||||
func (md *Model) Value() (Value, error) {
|
||||
one, err := md.One()
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range one {
|
||||
return v, nil
|
||||
}
|
||||
return "", nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 链式操作,查询数量,fields可以为空,也可以自定义查询字段,
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"gitee.com/johng/gf/g/util/gconv"
|
||||
)
|
||||
|
||||
func (v Value) Bytes() []byte { return gconv.Bytes(v) }
|
||||
func (v Value) Bytes() []byte { return []byte(v) }
|
||||
func (v Value) String() string { return string(v) }
|
||||
func (v Value) Bool() bool { return gconv.Bool(v) }
|
||||
|
||||
|
||||
@ -282,7 +282,7 @@ func linkopSelect3() {
|
||||
fmt.Println("linkopSelect3:")
|
||||
r, err := db.Table("user u").LeftJoin("user_detail ud", "u.uid=ud.uid").Fields("ud.site").Where("u.uid=?", 1).Value()
|
||||
if err == nil {
|
||||
fmt.Println(r.(string))
|
||||
fmt.Println(r.String())
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user