@@ -109,46 +109,46 @@ func (dba *Orm) _unionBuild(union, field string) (interface{}, error) {
109109}
110110
111111// Get : select more rows , relation limit set
112- func (dba * Orm ) Value (field string ) (v t. T , err error ) {
112+ func (dba * Orm ) Value (field string ) (v interface {} , err error ) {
113113 dba .Limit (1 )
114114 err = dba .Select ()
115115 if err != nil {
116116 return
117117 }
118- // var binder = dba.GetISession().GetIBinder()
119- // switch binder.GetBindType() {
120- // case OBJECT_MAP, OBJECT_MAP_SLICE, OBJECT_MAP_SLICE_T, OBJECT_MAP_T:
121- // v = t.New (binder.GetBindResult().MapIndex(reflect.ValueOf(field)).Interface() )
122- // case OBJECT_STRUCT, OBJECT_STRUCT_SLICE:
123- // bindResult := reflect.Indirect(binder.GetBindResult())
124- // v = dba._valueFromStruct(bindResult, field)
125- // }
118+ var binder = dba .GetISession ().GetIBinder ()
119+ switch binder .GetBindType () {
120+ case OBJECT_MAP , OBJECT_MAP_SLICE , OBJECT_MAP_SLICE_T , OBJECT_MAP_T :
121+ v = reflect . ValueOf (binder .GetBindResult ()) .MapIndex (reflect .ValueOf (field )).Interface ()
122+ case OBJECT_STRUCT , OBJECT_STRUCT_SLICE :
123+ bindResult := reflect .Indirect (reflect . ValueOf ( binder .GetBindResult () ))
124+ v = dba ._valueFromStruct (bindResult , field )
125+ }
126126 return
127127}
128- func (dba * Orm ) _valueFromStruct (bindResult reflect.Value , field string ) (v t. T ) {
128+ func (dba * Orm ) _valueFromStruct (bindResult reflect.Value , field string ) (v interface {} ) {
129129 ostype := bindResult .Type ()
130130 for i := 0 ; i < ostype .NumField (); i ++ {
131131 tag := ostype .Field (i ).Tag .Get (TAGNAME )
132132 if tag == field || ostype .Field (i ).Name == field {
133- v = t . New ( bindResult .FieldByName (ostype .Field (i ).Name ))
133+ v = bindResult .FieldByName (ostype .Field (i ).Name ). Interface ( )
134134 }
135135 }
136136 return
137137}
138138
139139// Pluck 获取一列数据, 第二个字段可以指定另一个字段的值作为这一列数据的key
140- func (dba * Orm ) Pluck (field string , fieldKey ... string ) (v t. T , err error ) {
140+ func (dba * Orm ) Pluck (field string , fieldKey ... string ) (v interface {} , err error ) {
141141 err = dba .Select ()
142142 if err != nil {
143143 return
144144 }
145145 var binder = dba .GetISession ().GetIBinder ()
146- var resMap = make (t. MapStringInterface , 0 )
147- var resSlice = t. Slice {}
146+ var resMap = make (map [ interface {}] interface {} , 0 )
147+ var resSlice = make ([] interface {}, 0 )
148148
149149 switch binder .GetBindType () {
150150 case OBJECT_MAP , OBJECT_MAP_T , OBJECT_STRUCT : // row
151- var key , val t. T
151+ var key , val interface {}
152152 if len (fieldKey ) > 0 {
153153 key , err = dba .Value (fieldKey [0 ])
154154 if err != nil {
@@ -158,21 +158,20 @@ func (dba *Orm) Pluck(field string, fieldKey ...string) (v t.T, err error) {
158158 if err != nil {
159159 return
160160 }
161- v = t . New (t. Map { key : val })
161+ resMap [ key ] = val
162162 } else {
163163 v , err = dba .Value (field )
164164 if err != nil {
165165 return
166166 }
167167 }
168- return
169168 case OBJECT_MAP_SLICE , OBJECT_MAP_SLICE_T :
170169 for _ , item := range t .New (binder .GetBindResultSlice ().Interface ()).Slice () {
171170 val := item .MapInterface ()
172171 if len (fieldKey ) > 0 {
173- resMap [val [fieldKey [0 ]].String ()] = val [field ]
172+ resMap [val [fieldKey [0 ]].Interface ()] = val [field ]. Interface ()
174173 } else {
175- resSlice = append (resSlice , val [field ])
174+ resSlice = append (resSlice , val [field ]. Interface () )
176175 }
177176 }
178177 case OBJECT_STRUCT_SLICE : // rows
@@ -182,16 +181,16 @@ func (dba *Orm) Pluck(field string, fieldKey ...string) (v t.T, err error) {
182181 if len (fieldKey ) > 0 {
183182 mapkey := dba ._valueFromStruct (val , fieldKey [0 ])
184183 mapVal := dba ._valueFromStruct (val , field )
185- resMap [mapkey . String () ] = mapVal
184+ resMap [mapkey ] = mapVal
186185 } else {
187186 resSlice = append (resSlice , dba ._valueFromStruct (val , field ))
188187 }
189188 }
190189 }
191190 if len (fieldKey ) > 0 {
192- v = t . New ( t . New ( resMap ). Map ())
191+ v = resMap
193192 } else {
194- v = t . New ( resSlice )
193+ v = resSlice
195194 }
196195 return
197196}
0 commit comments