-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbody.go
71 lines (57 loc) · 1.45 KB
/
body.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
package preform
import preformShare "github.com/go-preform/preform/share"
type hasQueryFactory[F IQuery] interface {
Factory() F
}
type hasFactory[F IFactory] interface {
Factory() F
}
type iModelBodyReadOnly interface {
FieldValueImmutablePtrs() []any
}
type iModelBody interface {
iModelBodyReadOnly
FieldValuePtrs() []interface{}
FieldValuePtr(pos int) interface{}
setFactory(defaultFactory IFactory)
}
type QueryBody[T hasQueryFactory[F], F IQuery] struct{}
func (b QueryBody[T, F]) getQueryFactory() IQuery {
var (
bb T
)
return bb.Factory()
}
type Body[T hasFactory[F], F IFactory] struct {
QueryBody[T, F]
hasFactory bool
factory F
}
func (b Body[T, F]) getFactory() IFactory {
var (
bb T
)
return bb.Factory()
}
func (b *Body[T, F]) setFactory(defaultFactory IFactory) {
b.factory = defaultFactory.(F)
b.hasFactory = true
}
func (b Body[T, F]) Factory(defaultFactory F) F {
if !b.hasFactory {
return defaultFactory
}
return b.factory
}
func (b Body[T, F]) SetCol(body *T, col preformShare.ICol, value any) {
any(col).(ICol).setValueToBody(any(body).(iModelBody), value)
}
func (b Body[T, F]) Insert(body *T, cfg ...EditConfig) error {
return (*body).Factory().Insert(body, cfg...)
}
func (b Body[T, F]) UpdateByPk(body *T, cfg ...UpdateConfig) (affected int64, err error) {
return (*body).Factory().UpdateByPk(body, cfg...)
}
func (b Body[T, F]) Delete(body *T, cfg ...EditConfig) (affected int64, err error) {
return 0, nil
}