Compare commits

..

4 Commits

7 changed files with 87 additions and 58 deletions

View File

@ -17,6 +17,7 @@ import (
"github.com/gogf/gf/g/util/gconv"
"reflect"
"strings"
"time"
)
// 格式化SQL查询条件
@ -136,6 +137,10 @@ func convertParam(value interface{}) interface{} {
}
switch kind {
case reflect.Struct:
// 底层数据库引擎支持 time.Time 类型
if _, ok := value.(time.Time); ok {
return value
}
return gconv.String(value)
}
return value

View File

@ -71,7 +71,7 @@ func Test_Stats(t *testing.T) {
redis.SetIdleTimeout(500*time.Millisecond)
redis.SetMaxConnLifetime(500*time.Millisecond)
array := make([]gredis.Conn, 0)
array := make([]*gredis.Conn, 0)
for i := 0; i < 10; i++ {
array = append(array, redis.Conn())
}

View File

@ -9,20 +9,19 @@
package glog
import (
"errors"
"fmt"
"github.com/gogf/gf/g/container/gtype"
"github.com/gogf/gf/g/os/gfile"
"github.com/gogf/gf/g/os/gfpool"
"github.com/gogf/gf/g/os/gmlock"
"github.com/gogf/gf/g/os/gtime"
"github.com/gogf/gf/g/text/gregex"
"io"
"os"
"runtime"
"strings"
"sync"
"time"
"errors"
"fmt"
"github.com/gogf/gf/g/container/gtype"
"github.com/gogf/gf/g/os/gfile"
"github.com/gogf/gf/g/os/gfpool"
"github.com/gogf/gf/g/os/gtime"
"github.com/gogf/gf/g/text/gregex"
"io"
"os"
"runtime"
"strings"
"sync"
"time"
)
type Logger struct {
@ -216,11 +215,7 @@ func (l *Logger) print(std io.Writer, s string) {
if _, ok := writer.(*Writer); ok {
if f := l.getFilePointer(); f != nil {
defer f.Close()
key := l.path.Val()
gmlock.Lock(key)
_, err := io.WriteString(f, s)
gmlock.Unlock(key)
if err != nil {
if _, err := io.WriteString(f, s); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
}

View File

@ -7,10 +7,10 @@
package gconv_test
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/test/gtest"
"github.com/gogf/gf/g/util/gconv"
"testing"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/test/gtest"
"github.com/gogf/gf/g/util/gconv"
"testing"
)
@ -113,7 +113,6 @@ func Test_Map_StructWithJsonTag(t *testing.T) {
})
}
// 私有属性不会进行转换
func Test_Map_PrivateAttribute(t *testing.T) {
type User struct {
Id int
@ -123,4 +122,24 @@ func Test_Map_PrivateAttribute(t *testing.T) {
user := &User{1, "john"}
gtest.Assert(gconv.Map(user), g.Map{"Id" : 1})
})
}
}
//
//func Test_Map_StructInherit(t *testing.T) {
// type Base struct {
// Id int
// }
// type User struct {
// Base
// Name string
// }
// gtest.Case(t, func() {
// user := &User{
// Base : Base {
// Id : 100,
// },
// Name : "john",
// }
// fmt.Println(gconv.Map(user))
// //gtest.Assert(gconv.Map(user), g.Map{"Id" : 1})
// })
//}

View File

@ -0,0 +1,26 @@
package main
import (
"fmt"
"github.com/gogf/gf/g"
"time"
)
func main() {
db := g.DB()
// 开启调试模式以便于记录所有执行的SQL
db.SetDebug(true)
r, e := db.Table("user").Data(g.Map{
"passport" : "1",
"password" : "1",
"nickname" : "1",
"create_time" : time.Now(),
}).Insert()
if e != nil {
panic(e)
}
if r != nil {
fmt.Println(r.LastInsertId())
}
}

View File

@ -1,40 +1,24 @@
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/util/gconv"
)
func main() {
//b, e := gjson.MarshalOrdered(g.Map{
// "a" : 1,
// "b" : 2,
// "c" : 3,
//})
//fmt.Println(e)
//fmt.Println(string(b))
//m := map[string]interface{}{
// "facet_is_special_price":[]string{"1"},
// "score_outlet":"0",
// "skus":[]string{"DI139BE71WDWDFMX", "DI139BE71WDWDFMX-519406"},
// "facet_novelty_two_days":[]string{"0"},
// "facet_brand":[]string{"139"},
// "sku":[]string{"DI139BE71WDWDFMX"},
//}
for {
m := make(map[string]interface{})
m["facet_is_special_price"] = []string{"1"}
m["score_outlet"] = "0"
m["skus"] = []string{"DI139BE71WDWDFMX", "DI139BE71WDWDFMX-519406"}
m["facet_novelty_two_days"] = []string{"0"}
m["facet_brand"] = []string{"139"}
m["sku"] = []string{"DI139BE71WDWDFMX"}
b, _ := json.Marshal(m)
fmt.Println(string(b))
time.Sleep(100*time.Millisecond)
type Person struct{
Name string
}
type Staff struct{
Person
StaffId int
}
staff := &Staff{}
params := g.Map{
"Name" : "john",
"StaffId" : "10000",
}
gconv.Struct(params, staff)
fmt.Println(staff)
}

View File

@ -1,4 +1,4 @@
package gf
const VERSION = "v1.6.12"
const VERSION = "v1.6.13"
const AUTHORS = "john<john@goframe.org>"