Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 198f3ebb5d | |||
| 2185a61564 | |||
|
fb9808a139
|
+13
-4
@@ -26,7 +26,9 @@ func (star *StarRows) setAllRefValue(stc interface{}, skey string, rows int) err
|
||||
tp := t.Field(i)
|
||||
srFrd := v.Field(i)
|
||||
seg := tp.Tag.Get(skey)
|
||||
|
||||
if seg == "" && !tp.IsExported() {
|
||||
continue
|
||||
}
|
||||
if srFrd.Kind() == reflect.Ptr && reflect.TypeOf(srFrd.Interface()).Elem().Kind() == reflect.Struct {
|
||||
if seg == "" {
|
||||
continue
|
||||
@@ -49,9 +51,6 @@ func (star *StarRows) setAllRefValue(stc interface{}, skey string, rows int) err
|
||||
continue
|
||||
}
|
||||
}
|
||||
if seg == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := star.Row(rows).columnref[seg]; !ok {
|
||||
continue
|
||||
}
|
||||
@@ -82,6 +81,10 @@ func (star *StarRows) setAllRefValue(stc interface{}, skey string, rows int) err
|
||||
v.Field(i).SetFloat(star.Row(rows).MustFloat64(seg))
|
||||
case reflect.Float32:
|
||||
v.Field(i).SetFloat(float64(star.Row(rows).MustFloat32(seg)))
|
||||
case reflect.Slice, reflect.Array:
|
||||
if t.Field(i).Type.Elem().Kind() == reflect.Uint8 {
|
||||
v.Field(i).SetBytes(star.Row(rows).MustBytes(seg))
|
||||
}
|
||||
case reflect.Interface, reflect.Struct, reflect.Ptr:
|
||||
inf := star.Row(rows).Result[star.columnref[seg]]
|
||||
switch vtype := inf.(type) {
|
||||
@@ -134,6 +137,9 @@ func getAllRefValue(stc interface{}, skey string) (map[string]interface{}, error
|
||||
tp := t.Field(i)
|
||||
srFrd := v.Field(i)
|
||||
seg := tp.Tag.Get(skey)
|
||||
if seg == "" && !tp.IsExported() {
|
||||
continue
|
||||
}
|
||||
if srFrd.Kind() == reflect.Ptr && reflect.TypeOf(srFrd.Interface()).Elem().Kind() == reflect.Struct {
|
||||
if srFrd.IsNil() {
|
||||
continue
|
||||
@@ -192,6 +198,9 @@ func getAllRefKey(stc interface{}, skey string) ([]string, error) {
|
||||
srFrd := v.Field(i)
|
||||
profile := t.Field(i)
|
||||
seg := profile.Tag.Get(skey)
|
||||
if seg == "" && !profile.IsExported() {
|
||||
continue
|
||||
}
|
||||
if srFrd.Kind() == reflect.Ptr && reflect.TypeOf(srFrd.Interface()).Elem().Kind() == reflect.Struct {
|
||||
if srFrd.IsNil() {
|
||||
continue
|
||||
|
||||
@@ -9,6 +9,7 @@ type Useless struct {
|
||||
Leader string `db:"leader"`
|
||||
Usable bool `db:"use"`
|
||||
O *Whoami `db:"---"`
|
||||
Data []byte `db:"data"`
|
||||
}
|
||||
|
||||
type Whoami struct {
|
||||
@@ -29,10 +30,15 @@ func TestUpInOrm(t *testing.T) {
|
||||
func Test_SetRefVal(t *testing.T) {
|
||||
var hehe = Useless{
|
||||
Leader: "no",
|
||||
Data: []byte{1, 2, 3},
|
||||
}
|
||||
fmt.Printf("%+v\n", hehe)
|
||||
fmt.Println(setRefValue(&hehe, "db", "leader", "sb"))
|
||||
fmt.Printf("%+v\n", hehe)
|
||||
fmt.Println(getAllRefKey(hehe, "db"))
|
||||
fmt.Println(getAllRefValue(hehe, "db"))
|
||||
|
||||
fmt.Println(setRefValue(&hehe, "db", "data", []byte{4, 5, 6, 7, 8}))
|
||||
fmt.Printf("%+v\n", hehe)
|
||||
fmt.Println(getAllRefKey(hehe, "db"))
|
||||
fmt.Println(getAllRefValue(hehe, "db"))
|
||||
|
||||
Reference in New Issue
Block a user