-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapping.go
44 lines (38 loc) · 963 Bytes
/
mapping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package go_orm
import (
"reflect"
)
/**
封装返回值
*/
func resultMapping(v reflect.Value, result *[]interface{}, fields []string) interface{} {
for i:=0;i< len(fields);i++ {
if v.FieldByName(fields[i]).Type().Kind()==reflect.Bool {
if (*result)[i] == int64(1){
v.FieldByName(fields[i]).Set(reflect.ValueOf(true))
}else {
v.FieldByName(fields[i]).Set(reflect.ValueOf(false))
}
}else{
v.FieldByName(fields[i]).Set(reflect.ValueOf((*result)[i]))
}
}
return v.Interface()
}
/**
封装查询结果
*/
func resultMappingFieldValueMap(v reflect.Value, result *map[string]interface{}) interface{} {
for field,value := range *result{
if v.FieldByName(field).Type().Kind()==reflect.Bool {
if value == int64(1){
v.FieldByName(field).Set(reflect.ValueOf(true))
}else {
v.FieldByName(field).Set(reflect.ValueOf(false))
}
}else{
v.FieldByName(field).Set(reflect.ValueOf(value))
}
}
return v.Interface()
}