mirror of
https://gitee.com/johng/gf
synced 2026-07-07 14:25:17 +08:00
fix issue 2403 (#2404)
This commit is contained in:
@ -9,8 +9,11 @@ package mysql_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/gmeta"
|
||||
)
|
||||
|
||||
func Test_Model_Builder(t *testing.T) {
|
||||
@ -59,4 +62,66 @@ func Test_Model_Builder(t *testing.T) {
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(all), 6)
|
||||
})
|
||||
|
||||
// Where with struct which has a field type of *gtime.Time
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m := db.Model(table)
|
||||
b := m.Builder()
|
||||
|
||||
type Query struct {
|
||||
Id interface{}
|
||||
Nickname *gtime.Time
|
||||
}
|
||||
|
||||
where, args := b.Where(&Query{Id: 1}).Build()
|
||||
t.Assert(where, "`id`=? AND `nickname` IS NULL")
|
||||
t.Assert(args, []interface{}{1})
|
||||
})
|
||||
|
||||
// Where with struct which has a field type of *gjson.Json
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m := db.Model(table)
|
||||
b := m.Builder()
|
||||
|
||||
type Query struct {
|
||||
Id interface{}
|
||||
Nickname *gjson.Json
|
||||
}
|
||||
|
||||
where, args := b.Where(&Query{Id: 1}).Build()
|
||||
t.Assert(where, "`id`=? AND `nickname` IS NULL")
|
||||
t.Assert(args, []interface{}{1})
|
||||
})
|
||||
|
||||
// Where with do struct which has a field type of *gtime.Time and generated by gf cli
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m := db.Model(table)
|
||||
b := m.Builder()
|
||||
|
||||
type Query struct {
|
||||
gmeta.Meta `orm:"do:true"`
|
||||
Id interface{}
|
||||
Nickname *gtime.Time
|
||||
}
|
||||
|
||||
where, args := b.Where(&Query{Id: 1}).Build()
|
||||
t.Assert(where, "`id`=?")
|
||||
t.Assert(args, []interface{}{1})
|
||||
})
|
||||
|
||||
// Where with do struct which has a field type of *gjson.Json and generated by gf cli
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m := db.Model(table)
|
||||
b := m.Builder()
|
||||
|
||||
type Query struct {
|
||||
gmeta.Meta `orm:"do:true"`
|
||||
Id interface{}
|
||||
Nickname *gjson.Json
|
||||
}
|
||||
|
||||
where, args := b.Where(&Query{Id: 1}).Build()
|
||||
t.Assert(where, "`id`=?")
|
||||
t.Assert(args, []interface{}{1})
|
||||
})
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/internal/empty"
|
||||
"github.com/gogf/gf/v2/internal/reflection"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
@ -210,7 +211,7 @@ func DataToMapDeep(value interface{}) map[string]interface{} {
|
||||
m := gconv.Map(value, structTagPriority...)
|
||||
for k, v := range m {
|
||||
switch v.(type) {
|
||||
case time.Time, *time.Time, gtime.Time, *gtime.Time:
|
||||
case time.Time, *time.Time, gtime.Time, *gtime.Time, gjson.Json, *gjson.Json:
|
||||
m[k] = v
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user