This commit is contained in:
John Guo
2025-01-09 14:46:59 +08:00
parent 73b5bfaccc
commit da5fc0ec4b
2 changed files with 124 additions and 126 deletions

View File

@ -17,7 +17,6 @@ import (
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gcode"
@ -3989,14 +3988,14 @@ func Test_ScanList_NoRecreate_PtrAttribute(t *testing.T) {
)
r1 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"name": gvar.New("john"),
"age": gvar.New(16),
"id": gdb.NewValue(1),
"name": gdb.NewValue("john"),
"age": gdb.NewValue(16),
},
gdb.Record{
"id": gvar.New(2),
"name": gvar.New("smith"),
"age": gvar.New(18),
"id": gdb.NewValue(2),
"name": gdb.NewValue("smith"),
"age": gdb.NewValue(18),
},
}
err = r1.ScanList(&s, "One")
@ -4009,12 +4008,12 @@ func Test_ScanList_NoRecreate_PtrAttribute(t *testing.T) {
r2 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"age": gvar.New(20),
"id": gdb.NewValue(1),
"age": gdb.NewValue(20),
},
gdb.Record{
"id": gvar.New(2),
"age": gvar.New(21),
"id": gdb.NewValue(2),
"age": gdb.NewValue(21),
},
}
err = r2.ScanList(&s, "One", "One", "id:Id")
@ -4045,14 +4044,14 @@ func Test_ScanList_NoRecreate_StructAttribute(t *testing.T) {
)
r1 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"name": gvar.New("john"),
"age": gvar.New(16),
"id": gdb.NewValue(1),
"name": gdb.NewValue("john"),
"age": gdb.NewValue(16),
},
gdb.Record{
"id": gvar.New(2),
"name": gvar.New("smith"),
"age": gvar.New(18),
"id": gdb.NewValue(2),
"name": gdb.NewValue("smith"),
"age": gdb.NewValue(18),
},
}
err = r1.ScanList(&s, "One")
@ -4065,12 +4064,12 @@ func Test_ScanList_NoRecreate_StructAttribute(t *testing.T) {
r2 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"age": gvar.New(20),
"id": gdb.NewValue(1),
"age": gdb.NewValue(20),
},
gdb.Record{
"id": gvar.New(2),
"age": gvar.New(21),
"id": gdb.NewValue(2),
"age": gdb.NewValue(21),
},
}
err = r2.ScanList(&s, "One", "One", "id:Id")
@ -4109,14 +4108,14 @@ func Test_ScanList_NoRecreate_SliceAttribute_Ptr(t *testing.T) {
)
r1 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"name": gvar.New("john"),
"age": gvar.New(16),
"id": gdb.NewValue(1),
"name": gdb.NewValue("john"),
"age": gdb.NewValue(16),
},
gdb.Record{
"id": gvar.New(2),
"name": gvar.New("smith"),
"age": gvar.New(18),
"id": gdb.NewValue(2),
"name": gdb.NewValue("smith"),
"age": gdb.NewValue(18),
},
}
err = r1.ScanList(&s, "One")
@ -4129,16 +4128,16 @@ func Test_ScanList_NoRecreate_SliceAttribute_Ptr(t *testing.T) {
r2 := gdb.Result{
gdb.Record{
"id": gvar.New(100),
"pid": gvar.New(1),
"age": gvar.New(30),
"name": gvar.New("john"),
"id": gdb.NewValue(100),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(30),
"name": gdb.NewValue("john"),
},
gdb.Record{
"id": gvar.New(200),
"pid": gvar.New(1),
"age": gvar.New(31),
"name": gvar.New("smith"),
"id": gdb.NewValue(200),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(31),
"name": gdb.NewValue("smith"),
},
}
err = r2.ScanList(&s, "Many", "One", "pid:Id")
@ -4159,14 +4158,14 @@ func Test_ScanList_NoRecreate_SliceAttribute_Ptr(t *testing.T) {
r3 := gdb.Result{
gdb.Record{
"id": gvar.New(100),
"pid": gvar.New(1),
"age": gvar.New(40),
"id": gdb.NewValue(100),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(40),
},
gdb.Record{
"id": gvar.New(200),
"pid": gvar.New(1),
"age": gvar.New(41),
"id": gdb.NewValue(200),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(41),
},
}
err = r3.ScanList(&s, "Many", "One", "pid:Id")
@ -4213,14 +4212,14 @@ func Test_ScanList_NoRecreate_SliceAttribute_Struct(t *testing.T) {
)
r1 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"name": gvar.New("john"),
"age": gvar.New(16),
"id": gdb.NewValue(1),
"name": gdb.NewValue("john"),
"age": gdb.NewValue(16),
},
gdb.Record{
"id": gvar.New(2),
"name": gvar.New("smith"),
"age": gvar.New(18),
"id": gdb.NewValue(2),
"name": gdb.NewValue("smith"),
"age": gdb.NewValue(18),
},
}
err = r1.ScanList(&s, "One")
@ -4233,16 +4232,16 @@ func Test_ScanList_NoRecreate_SliceAttribute_Struct(t *testing.T) {
r2 := gdb.Result{
gdb.Record{
"id": gvar.New(100),
"pid": gvar.New(1),
"age": gvar.New(30),
"name": gvar.New("john"),
"id": gdb.NewValue(100),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(30),
"name": gdb.NewValue("john"),
},
gdb.Record{
"id": gvar.New(200),
"pid": gvar.New(1),
"age": gvar.New(31),
"name": gvar.New("smith"),
"id": gdb.NewValue(200),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(31),
"name": gdb.NewValue("smith"),
},
}
err = r2.ScanList(&s, "Many", "One", "pid:Id")
@ -4263,14 +4262,14 @@ func Test_ScanList_NoRecreate_SliceAttribute_Struct(t *testing.T) {
r3 := gdb.Result{
gdb.Record{
"id": gvar.New(100),
"pid": gvar.New(1),
"age": gvar.New(40),
"id": gdb.NewValue(100),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(40),
},
gdb.Record{
"id": gvar.New(200),
"pid": gvar.New(1),
"age": gvar.New(41),
"id": gdb.NewValue(200),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(41),
},
}
err = r3.ScanList(&s, "Many", "One", "pid:Id")
@ -4301,8 +4300,8 @@ func TestResult_Structs1(t *testing.T) {
}
gtest.C(t, func(t *gtest.T) {
r := gdb.Result{
gdb.Record{"id": gvar.New(nil), "name": gvar.New("john")},
gdb.Record{"id": gvar.New(nil), "name": gvar.New("smith")},
gdb.Record{"id": gdb.NewValue(nil), "name": gdb.NewValue("john")},
gdb.Record{"id": gdb.NewValue(nil), "name": gdb.NewValue("smith")},
}
array := make([]*B, 2)
err := r.Structs(&array)

View File

@ -17,7 +17,6 @@ import (
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gcode"
@ -4037,14 +4036,14 @@ func Test_ScanList_NoRecreate_PtrAttribute(t *testing.T) {
)
r1 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"name": gvar.New("john"),
"age": gvar.New(16),
"id": gdb.NewValue(1),
"name": gdb.NewValue("john"),
"age": gdb.NewValue(16),
},
gdb.Record{
"id": gvar.New(2),
"name": gvar.New("smith"),
"age": gvar.New(18),
"id": gdb.NewValue(2),
"name": gdb.NewValue("smith"),
"age": gdb.NewValue(18),
},
}
err = r1.ScanList(&s, "One")
@ -4057,12 +4056,12 @@ func Test_ScanList_NoRecreate_PtrAttribute(t *testing.T) {
r2 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"age": gvar.New(20),
"id": gdb.NewValue(1),
"age": gdb.NewValue(20),
},
gdb.Record{
"id": gvar.New(2),
"age": gvar.New(21),
"id": gdb.NewValue(2),
"age": gdb.NewValue(21),
},
}
err = r2.ScanList(&s, "One", "One", "id:Id")
@ -4093,14 +4092,14 @@ func Test_ScanList_NoRecreate_StructAttribute(t *testing.T) {
)
r1 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"name": gvar.New("john"),
"age": gvar.New(16),
"id": gdb.NewValue(1),
"name": gdb.NewValue("john"),
"age": gdb.NewValue(16),
},
gdb.Record{
"id": gvar.New(2),
"name": gvar.New("smith"),
"age": gvar.New(18),
"id": gdb.NewValue(2),
"name": gdb.NewValue("smith"),
"age": gdb.NewValue(18),
},
}
err = r1.ScanList(&s, "One")
@ -4113,12 +4112,12 @@ func Test_ScanList_NoRecreate_StructAttribute(t *testing.T) {
r2 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"age": gvar.New(20),
"id": gdb.NewValue(1),
"age": gdb.NewValue(20),
},
gdb.Record{
"id": gvar.New(2),
"age": gvar.New(21),
"id": gdb.NewValue(2),
"age": gdb.NewValue(21),
},
}
err = r2.ScanList(&s, "One", "One", "id:Id")
@ -4157,14 +4156,14 @@ func Test_ScanList_NoRecreate_SliceAttribute_Ptr(t *testing.T) {
)
r1 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"name": gvar.New("john"),
"age": gvar.New(16),
"id": gdb.NewValue(1),
"name": gdb.NewValue("john"),
"age": gdb.NewValue(16),
},
gdb.Record{
"id": gvar.New(2),
"name": gvar.New("smith"),
"age": gvar.New(18),
"id": gdb.NewValue(2),
"name": gdb.NewValue("smith"),
"age": gdb.NewValue(18),
},
}
err = r1.ScanList(&s, "One")
@ -4177,16 +4176,16 @@ func Test_ScanList_NoRecreate_SliceAttribute_Ptr(t *testing.T) {
r2 := gdb.Result{
gdb.Record{
"id": gvar.New(100),
"pid": gvar.New(1),
"age": gvar.New(30),
"name": gvar.New("john"),
"id": gdb.NewValue(100),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(30),
"name": gdb.NewValue("john"),
},
gdb.Record{
"id": gvar.New(200),
"pid": gvar.New(1),
"age": gvar.New(31),
"name": gvar.New("smith"),
"id": gdb.NewValue(200),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(31),
"name": gdb.NewValue("smith"),
},
}
err = r2.ScanList(&s, "Many", "One", "pid:Id")
@ -4207,14 +4206,14 @@ func Test_ScanList_NoRecreate_SliceAttribute_Ptr(t *testing.T) {
r3 := gdb.Result{
gdb.Record{
"id": gvar.New(100),
"pid": gvar.New(1),
"age": gvar.New(40),
"id": gdb.NewValue(100),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(40),
},
gdb.Record{
"id": gvar.New(200),
"pid": gvar.New(1),
"age": gvar.New(41),
"id": gdb.NewValue(200),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(41),
},
}
err = r3.ScanList(&s, "Many", "One", "pid:Id")
@ -4261,14 +4260,14 @@ func Test_ScanList_NoRecreate_SliceAttribute_Struct(t *testing.T) {
)
r1 := gdb.Result{
gdb.Record{
"id": gvar.New(1),
"name": gvar.New("john"),
"age": gvar.New(16),
"id": gdb.NewValue(1),
"name": gdb.NewValue("john"),
"age": gdb.NewValue(16),
},
gdb.Record{
"id": gvar.New(2),
"name": gvar.New("smith"),
"age": gvar.New(18),
"id": gdb.NewValue(2),
"name": gdb.NewValue("smith"),
"age": gdb.NewValue(18),
},
}
err = r1.ScanList(&s, "One")
@ -4281,16 +4280,16 @@ func Test_ScanList_NoRecreate_SliceAttribute_Struct(t *testing.T) {
r2 := gdb.Result{
gdb.Record{
"id": gvar.New(100),
"pid": gvar.New(1),
"age": gvar.New(30),
"name": gvar.New("john"),
"id": gdb.NewValue(100),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(30),
"name": gdb.NewValue("john"),
},
gdb.Record{
"id": gvar.New(200),
"pid": gvar.New(1),
"age": gvar.New(31),
"name": gvar.New("smith"),
"id": gdb.NewValue(200),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(31),
"name": gdb.NewValue("smith"),
},
}
err = r2.ScanList(&s, "Many", "One", "pid:Id")
@ -4311,14 +4310,14 @@ func Test_ScanList_NoRecreate_SliceAttribute_Struct(t *testing.T) {
r3 := gdb.Result{
gdb.Record{
"id": gvar.New(100),
"pid": gvar.New(1),
"age": gvar.New(40),
"id": gdb.NewValue(100),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(40),
},
gdb.Record{
"id": gvar.New(200),
"pid": gvar.New(1),
"age": gvar.New(41),
"id": gdb.NewValue(200),
"pid": gdb.NewValue(1),
"age": gdb.NewValue(41),
},
}
err = r3.ScanList(&s, "Many", "One", "pid:Id")
@ -4349,8 +4348,8 @@ func TestResult_Structs1(t *testing.T) {
}
gtest.C(t, func(t *gtest.T) {
r := gdb.Result{
gdb.Record{"id": gvar.New(nil), "name": gvar.New("john")},
gdb.Record{"id": gvar.New(nil), "name": gvar.New("smith")},
gdb.Record{"id": gdb.NewValue(nil), "name": gdb.NewValue("john")},
gdb.Record{"id": gdb.NewValue(nil), "name": gdb.NewValue("smith")},
}
array := make([]*B, 2)
err := r.Structs(&array)