forked from s7techlab/cckit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_keyref.go
47 lines (38 loc) · 1.22 KB
/
state_keyref.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
package mapping
import (
"github.com/s7techlab/cckit/state"
"github.com/s7techlab/cckit/state/schema"
)
const KeyRefNamespace = `_idx`
var KeyRefIdKeyer = attrsPKeyer([]string{`Schema`, `Idx`, `RefKey`})
var KeyRefMapper = &StateMapping{
schema: &schema.KeyRef{},
namespace: state.Key{KeyRefNamespace},
primaryKeyer: KeyRefIdKeyer,
}
var KeyRefIdMapper = &StateMapping{
schema: &schema.KeyRefId{},
namespace: state.Key{KeyRefNamespace},
primaryKeyer: KeyRefIdKeyer,
}
func NewKeyRef(target interface{}, idx string, refKey, pKey state.Key) *schema.KeyRef {
return &schema.KeyRef{
Schema: mapKey(target),
Idx: idx,
RefKey: []string(refKey),
PKey: []string(pKey),
}
}
func NewKeyRefId(target interface{}, idx string, refKey state.Key) *schema.KeyRefId {
return &schema.KeyRefId{
Schema: mapKey(target),
Idx: idx,
RefKey: []string(refKey),
}
}
func NewKeyRefMapped(target interface{}, idx string, refKey, pKey state.Key) *ProtoStateMapped {
return NewProtoStateMapped(NewKeyRef(target, idx, refKey, pKey), KeyRefMapper)
}
func NewKeyRefIdMapped(target interface{}, idx string, refKey state.Key) *ProtoStateMapped {
return NewProtoStateMapped(NewKeyRefId(target, idx, refKey), KeyRefIdMapper)
}