-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdest_type_target.go
78 lines (67 loc) · 1.25 KB
/
dest_type_target.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package lorm
import (
"errors"
"reflect"
)
// 获取:参数,表名,scan
func (ctx *ormContext) initModelDest(dest any) {
if ctx.hasErr() {
return
}
v := reflect.ValueOf(dest)
isPtr, v, err := basePtrValue(v)
if err != nil {
ctx.err = err
return
}
ctx.scanIsPtr = isPtr
t := v.Type()
if ctx.checkParam {
if _isStructType(t) {
ctx.err = errors.New("dest need is struct")
return
}
err = checkCompFieldVS(v)
if err != nil {
ctx.err = err
return
}
}
ctx.paramModelBaseV = v
ctx.scanDest = dest
ctx.scanV = v
ctx.scanIsPtr = isPtr
ctx.destBaseValue = v
ctx.destBaseType = t
ctx.destBaseTypeIsComp = true
ctx.destIsSlice = false
ctx.destSliceItemIsPtr = false
}
// 只作为参数,主要用在insert,update时,获取更新的数据
func (ctx *ormContext) initTargetDestOne(dest any) {
if ctx.hasErr() {
return
}
v := reflect.ValueOf(dest)
_, v, err := basePtrValue(v)
if err != nil {
ctx.err = err
return
}
t := v.Type()
if ctx.checkParam {
if _isStructType(t) {
ctx.err = errors.New("dest need is struct")
return
}
err = checkCompFieldVS(v)
if err != nil {
ctx.err = err
return
}
}
ctx.paramModelBaseV = v
ctx.destBaseValue = v
ctx.destBaseType = t
ctx.destBaseTypeIsComp = true
}