完成gvar包的开发,并改进相关依赖包

This commit is contained in:
john
2018-10-09 13:33:00 +08:00
parent d09978c87d
commit e4c8e33210
13 changed files with 223 additions and 54 deletions

View File

@ -19,6 +19,7 @@ import (
"gitee.com/johng/gf/g/os/gcache"
"gitee.com/johng/gf/g/util/grand"
_ "github.com/go-sql-driver/mysql"
"gitee.com/johng/gf/g/container/gvar"
)
const (
@ -108,7 +109,7 @@ type Sql struct {
}
// 返回数据表记录值
type Value []byte
type Value = *gvar.Var
// 返回数据表记录Map
type Record map[string]Value

View File

@ -19,6 +19,7 @@ import (
"gitee.com/johng/gf/g/os/gtime"
"time"
"gitee.com/johng/gf/g/os/glog"
"gitee.com/johng/gf/g/container/gvar"
)
const (
@ -195,10 +196,9 @@ func (db *Db) GetAll(query string, args ...interface{}) (Result, error) {
row := make(Record)
// 注意col字段是一个[]byte类型(slice类型本身是一个指针),多个记录循环时该变量指向的是同一个内存地址
for i, col := range values {
k := columns[i]
v := make([]byte, len(col))
copy(v, col)
row[k] = v
row[columns[i]] = gvar.New(v)
}
records = append(records, row)
}

View File

@ -15,6 +15,7 @@ import (
"gitee.com/johng/gf/g/os/gtime"
"gitee.com/johng/gf/g/util/gconv"
_ "github.com/go-sql-driver/mysql"
"gitee.com/johng/gf/g/container/gvar"
)
// 数据库事务对象
@ -115,10 +116,9 @@ func (tx *Tx) GetAll(query string, args ...interface{}) (Result, error) {
row := make(Record)
// 注意col字段是一个[]byte类型(slice类型本身是一个指针),多个记录循环时该变量指向的是同一个内存地址
for i, col := range values {
k := columns[i]
v := make([]byte, len(col))
copy(v, col)
row[k] = v
row[columns[i]] = gvar.New(v)
}
//fmt.Printf("%p\n", row["typeid"])
records = append(records, row)

View File

@ -1,35 +0,0 @@
// Copyright 2018 gf Author(https://gitee.com/johng/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://gitee.com/johng/gf.
package gdb
import (
"time"
"gitee.com/johng/gf/g/util/gconv"
)
func (v Value) IsNil() bool { return v == nil }
func (v Value) Bytes() []byte { return []byte(v) }
func (v Value) String() string { return string(v.Bytes()) }
func (v Value) Bool() bool { return gconv.Bool(v.Bytes()) }
func (v Value) Int() int { return gconv.Int(v.Bytes()) }
func (v Value) Int8() int8 { return gconv.Int8(v.Bytes()) }
func (v Value) Int16() int16 { return gconv.Int16(v.Bytes()) }
func (v Value) Int32() int32 { return gconv.Int32(v.Bytes()) }
func (v Value) Int64() int64 { return gconv.Int64(v.Bytes()) }
func (v Value) Uint() uint { return gconv.Uint(v.Bytes()) }
func (v Value) Uint8() uint8 { return gconv.Uint8(v.Bytes()) }
func (v Value) Uint16() uint16 { return gconv.Uint16(v.Bytes()) }
func (v Value) Uint32() uint32 { return gconv.Uint32(v.Bytes()) }
func (v Value) Uint64() uint64 { return gconv.Uint64(v.Bytes()) }
func (v Value) Float32() float32 { return gconv.Float32(v.Bytes()) }
func (v Value) Float64() float64 { return gconv.Float64(v.Bytes()) }
func (v Value) Time(format...string) time.Time { return gconv.Time(v.Bytes(), format...) }
func (v Value) TimeDuration() time.Duration { return gconv.TimeDuration(v.Bytes()) }