修改gdb.Value类型的数据结构为[]byte,并改进ORM的Value方法,返回Value数据类型

This commit is contained in:
John
2018-05-01 13:02:20 +08:00
parent 32b3c443f6
commit ac7f81849b
5 changed files with 8 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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可以为空也可以自定义查询字段

View File

@ -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) }

View File

@ -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)
}