Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(database/gdb): json type field incorrect scanning to slice attribute #4107

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
789baf5
fix(database/gdb): json type field incorrect scanning to string slice…
gqcn Jan 9, 2025
0083153
gofmt
gqcn Jan 9, 2025
5fd1064
Apply gci import order changes
github-actions[bot] Jan 9, 2025
7d79aea
up
gqcn Jan 9, 2025
98ff5d4
Merge branch 'fix/4086' of github.com:gogf/gf into fix/4086
gqcn Jan 9, 2025
6316625
up
gqcn Jan 9, 2025
19c8036
up
gqcn Jan 9, 2025
2ae1684
up
gqcn Jan 9, 2025
185316c
up
gqcn Jan 9, 2025
73b5bfa
up
gqcn Jan 9, 2025
da5fc0e
up
gqcn Jan 9, 2025
4f069ef
merge master
gqcn Feb 27, 2025
67bb75a
fix: 4086
gqcn Feb 27, 2025
896edfb
Apply gci import order changes
github-actions[bot] Feb 27, 2025
ce2cf3c
up
gqcn Feb 28, 2025
e83d378
Merge branch 'fix/4086-fix' of github.com:gogf/gf into fix/4086-fix
gqcn Feb 28, 2025
e311630
up
gqcn Feb 28, 2025
0757ab7
up
gqcn Feb 28, 2025
dd8817f
up
gqcn Feb 28, 2025
dae543c
up
gqcn Feb 28, 2025
d0e0efb
up
gqcn Feb 28, 2025
d24245e
up
gqcn Feb 28, 2025
97c40a5
up
gqcn Feb 28, 2025
7f03024
up
gqcn Mar 2, 2025
da93839
Apply gci import order changes
github-actions[bot] Mar 2, 2025
d5e786c
up
gqcn Mar 2, 2025
1c1c145
Merge branch 'fix/4086-converter' of github.com:gogf/gf into fix/4086…
gqcn Mar 2, 2025
bd5b6a1
up
gqcn Mar 2, 2025
56a36f5
up
gqcn Mar 2, 2025
33a8d32
up
gqcn Mar 2, 2025
b52ba15
up
gqcn Mar 2, 2025
d7a246c
up
gqcn Mar 2, 2025
1c1558b
up
gqcn Mar 2, 2025
996b141
up
gqcn Mar 2, 2025
355ef48
up
gqcn Mar 2, 2025
d42d2c2
up
gqcn Mar 2, 2025
cb7ae2e
up
gqcn Mar 3, 2025
c031261
up
gqcn Mar 3, 2025
4912659
up
gqcn Mar 3, 2025
19446fc
up
gqcn Mar 3, 2025
9546cd6
up
gqcn Mar 3, 2025
7878530
up
gqcn Mar 3, 2025
ceafbfd
make lint
gqcn Mar 3, 2025
65172fb
make lint
gqcn Mar 3, 2025
f97a6fa
up
gqcn Mar 3, 2025
48cf952
merge master
gqcn Mar 3, 2025
23c7aae
up
gqcn Mar 3, 2025
6e43072
up
gqcn Mar 3, 2025
760799f
up
gqcn Mar 3, 2025
65a0d51
开放RegisterAnyConverterFunc接口
wln32 Mar 5, 2025
a4add90
1.支持接口类型的自定义转换
wln32 Mar 5, 2025
9c458ba
添加测试
wln32 Mar 5, 2025
4ac7359
补充测试
wln32 Mar 5, 2025
5feda53
supplement to PR #4107 (#4183)
wln32 Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ version:
subup:
@set -e; \
echo "Updating submodules..."; \
cd examples && git pull origin main; \
cd ..;
git submodule init;\
git submodule update;

# update and commit submodules
.PHONY: subsync
Expand Down
2 changes: 1 addition & 1 deletion cmd/gf/internal/cmd/gendao/gendao.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type (
Link string `name:"link" short:"l" brief:"{CGenDaoBriefLink}"`
Tables string `name:"tables" short:"t" brief:"{CGenDaoBriefTables}"`
TablesEx string `name:"tablesEx" short:"x" brief:"{CGenDaoBriefTablesEx}"`
ShardingPattern []string `name:"ShardingPattern" short:"sp" brief:"{CGenDaoBriefShardingPattern}"`
ShardingPattern []string `name:"shardingPattern" short:"sp" brief:"{CGenDaoBriefShardingPattern}"`
Group string `name:"group" short:"g" brief:"{CGenDaoBriefGroup}" d:"default"`
Prefix string `name:"prefix" short:"f" brief:"{CGenDaoBriefPrefix}"`
RemovePrefix string `name:"removePrefix" short:"r" brief:"{CGenDaoBriefRemovePrefix}"`
Expand Down
152 changes: 1 addition & 151 deletions container/gvar/gvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@
package gvar

import (
"time"

"github.com/gogf/gf/v2/container/gtype"
"github.com/gogf/gf/v2/internal/deepcopy"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gutil"
)

// Var is an universal variable type implementer.
Expand All @@ -39,144 +33,8 @@ func New(value interface{}, safe ...bool) *Var {
}
}

// Copy does a deep copy of current Var and returns a pointer to this Var.
func (v *Var) Copy() *Var {
return New(gutil.Copy(v.Val()), v.safe)
}

// Clone does a shallow copy of current Var and returns a pointer to this Var.
func (v *Var) Clone() *Var {
return New(v.Val(), v.safe)
}

// Set sets `value` to `v`, and returns the old value.
func (v *Var) Set(value interface{}) (old interface{}) {
if v.safe {
if t, ok := v.value.(*gtype.Interface); ok {
old = t.Set(value)
return
}
}
old = v.value
v.value = value
return
}

// Val returns the current value of `v`.
func (v *Var) Val() interface{} {
if v == nil {
return nil
}
if v.safe {
if t, ok := v.value.(*gtype.Interface); ok {
return t.Val()
}
}
return v.value
}

// Interface is alias of Val.
func (v *Var) Interface() interface{} {
return v.Val()
}

// Bytes converts and returns `v` as []byte.
func (v *Var) Bytes() []byte {
return gconv.Bytes(v.Val())
}

// String converts and returns `v` as string.
func (v *Var) String() string {
return gconv.String(v.Val())
}

// Bool converts and returns `v` as bool.
func (v *Var) Bool() bool {
return gconv.Bool(v.Val())
}

// Int converts and returns `v` as int.
func (v *Var) Int() int {
return gconv.Int(v.Val())
}

// Int8 converts and returns `v` as int8.
func (v *Var) Int8() int8 {
return gconv.Int8(v.Val())
}

// Int16 converts and returns `v` as int16.
func (v *Var) Int16() int16 {
return gconv.Int16(v.Val())
}

// Int32 converts and returns `v` as int32.
func (v *Var) Int32() int32 {
return gconv.Int32(v.Val())
}

// Int64 converts and returns `v` as int64.
func (v *Var) Int64() int64 {
return gconv.Int64(v.Val())
}

// Uint converts and returns `v` as uint.
func (v *Var) Uint() uint {
return gconv.Uint(v.Val())
}

// Uint8 converts and returns `v` as uint8.
func (v *Var) Uint8() uint8 {
return gconv.Uint8(v.Val())
}

// Uint16 converts and returns `v` as uint16.
func (v *Var) Uint16() uint16 {
return gconv.Uint16(v.Val())
}

// Uint32 converts and returns `v` as uint32.
func (v *Var) Uint32() uint32 {
return gconv.Uint32(v.Val())
}

// Uint64 converts and returns `v` as uint64.
func (v *Var) Uint64() uint64 {
return gconv.Uint64(v.Val())
}

// Float32 converts and returns `v` as float32.
func (v *Var) Float32() float32 {
return gconv.Float32(v.Val())
}

// Float64 converts and returns `v` as float64.
func (v *Var) Float64() float64 {
return gconv.Float64(v.Val())
}

// Time converts and returns `v` as time.Time.
// The parameter `format` specifies the format of the time string using gtime,
// eg: Y-m-d H:i:s.
func (v *Var) Time(format ...string) time.Time {
return gconv.Time(v.Val(), format...)
}

// Duration converts and returns `v` as time.Duration.
// If value of `v` is string, then it uses time.ParseDuration for conversion.
func (v *Var) Duration() time.Duration {
return gconv.Duration(v.Val())
}

// GTime converts and returns `v` as *gtime.Time.
// The parameter `format` specifies the format of the time string using gtime,
// eg: Y-m-d H:i:s.
func (v *Var) GTime(format ...string) *gtime.Time {
return gconv.GTime(v.Val(), format...)
}

// MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (v Var) MarshalJSON() ([]byte, error) {
func (v *Var) MarshalJSON() ([]byte, error) {
return json.Marshal(v.Val())
}

Expand All @@ -195,11 +53,3 @@ func (v *Var) UnmarshalValue(value interface{}) error {
v.Set(value)
return nil
}

// DeepCopy implements interface for deep copy of current type.
func (v *Var) DeepCopy() interface{} {
if v == nil {
return nil
}
return New(deepcopy.Copy(v.Val()), v.safe)
}
105 changes: 105 additions & 0 deletions container/gvar/gvar_basic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright GoFrame Author(https://goframe.org). 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://github.com/gogf/gf.

package gvar

import (
"github.com/gogf/gf/v2/container/gtype"
"github.com/gogf/gf/v2/util/gconv"
)

// Val returns the current value of `v`.
func (v *Var) Val() any {
if v == nil {
return nil
}
if v.safe {
if t, ok := v.value.(*gtype.Interface); ok {
return t.Val()
}
}
return v.value
}

// Interface is alias of Val.
func (v *Var) Interface() any {
return v.Val()
}

// Bytes converts and returns `v` as []byte.
func (v *Var) Bytes() []byte {
return gconv.Bytes(v.Val())
}

// String converts and returns `v` as string.
func (v *Var) String() string {
return gconv.String(v.Val())
}

// Bool converts and returns `v` as bool.
func (v *Var) Bool() bool {
return gconv.Bool(v.Val())
}

// Int converts and returns `v` as int.
func (v *Var) Int() int {
return gconv.Int(v.Val())
}

// Int8 converts and returns `v` as int8.
func (v *Var) Int8() int8 {
return gconv.Int8(v.Val())
}

// Int16 converts and returns `v` as int16.
func (v *Var) Int16() int16 {
return gconv.Int16(v.Val())
}

// Int32 converts and returns `v` as int32.
func (v *Var) Int32() int32 {
return gconv.Int32(v.Val())
}

// Int64 converts and returns `v` as int64.
func (v *Var) Int64() int64 {
return gconv.Int64(v.Val())
}

// Uint converts and returns `v` as uint.
func (v *Var) Uint() uint {
return gconv.Uint(v.Val())
}

// Uint8 converts and returns `v` as uint8.
func (v *Var) Uint8() uint8 {
return gconv.Uint8(v.Val())
}

// Uint16 converts and returns `v` as uint16.
func (v *Var) Uint16() uint16 {
return gconv.Uint16(v.Val())
}

// Uint32 converts and returns `v` as uint32.
func (v *Var) Uint32() uint32 {
return gconv.Uint32(v.Val())
}

// Uint64 converts and returns `v` as uint64.
func (v *Var) Uint64() uint64 {
return gconv.Uint64(v.Val())
}

// Float32 converts and returns `v` as float32.
func (v *Var) Float32() float32 {
return gconv.Float32(v.Val())
}

// Float64 converts and returns `v` as float64.
func (v *Var) Float64() float64 {
return gconv.Float64(v.Val())
}
30 changes: 30 additions & 0 deletions container/gvar/gvar_copy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright GoFrame Author(https://goframe.org). 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://github.com/gogf/gf.

package gvar

import (
"github.com/gogf/gf/v2/internal/deepcopy"
"github.com/gogf/gf/v2/util/gutil"
)

// Copy does a deep copy of current Var and returns a pointer to this Var.
func (v *Var) Copy() *Var {
return New(gutil.Copy(v.Val()), v.safe)
}

// Clone does a shallow copy of current Var and returns a pointer to this Var.
func (v *Var) Clone() *Var {
return New(v.Val(), v.safe)
}

// DeepCopy implements interface for deep copy of current type.
func (v *Var) DeepCopy() interface{} {
if v == nil {
return nil
}
return New(deepcopy.Copy(v.Val()), v.safe)
}
3 changes: 1 addition & 2 deletions container/gvar/gvar_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
"github.com/gogf/gf/v2/util/gconv"
)

// Scan automatically checks the type of `pointer` and converts `params` to `pointer`. It supports `pointer`
// with type of `*map/*[]map/*[]*map/*struct/**struct/*[]struct/*[]*struct` for converting.
// Scan automatically checks the type of `pointer` and converts value of Var to `pointer`.
//
// See gconv.Scan.
func (v *Var) Scan(pointer interface{}, mapping ...map[string]string) error {
Expand Down
24 changes: 24 additions & 0 deletions container/gvar/gvar_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright GoFrame Author(https://goframe.org). 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://github.com/gogf/gf.

package gvar

import (
"github.com/gogf/gf/v2/container/gtype"
)

// Set sets `value` to `v`, and returns the old value.
func (v *Var) Set(value interface{}) (old interface{}) {
if v.safe {
if t, ok := v.value.(*gtype.Interface); ok {
old = t.Set(value)
return
}
}
old = v.value
v.value = value
return
}
34 changes: 34 additions & 0 deletions container/gvar/gvar_time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright GoFrame Author(https://goframe.org). 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://github.com/gogf/gf.

package gvar

import (
"time"

"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
)

// Time converts and returns `v` as time.Time.
// The parameter `format` specifies the format of the time string using gtime,
// eg: Y-m-d H:i:s.
func (v *Var) Time(format ...string) time.Time {
return gconv.Time(v.Val(), format...)
}

// Duration converts and returns `v` as time.Duration.
// If value of `v` is string, then it uses time.ParseDuration for conversion.
func (v *Var) Duration() time.Duration {
return gconv.Duration(v.Val())
}

// GTime converts and returns `v` as *gtime.Time.
// The parameter `format` specifies the format of the time string using gtime,
// eg: Y-m-d H:i:s.
func (v *Var) GTime(format ...string) *gtime.Time {
return gconv.GTime(v.Val(), format...)
}
Loading
Loading