-
Notifications
You must be signed in to change notification settings - Fork 329
/
module_field_mapping.go
46 lines (36 loc) · 1.1 KB
/
module_field_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
43
44
45
46
package types
import (
"database/sql/driver"
"encoding/json"
"github.com/cortezaproject/corteza/server/pkg/sql"
)
const (
ModuleFieldMappingSetFindTypeOrigin ModuleFieldMappingSetFindType = iota
ModuleFieldMappingSetFindTypeDestination
)
type (
ModuleFieldMappingSet []*ModuleFieldMapping
ModuleFieldMapping struct {
Origin ModuleField `json:"origin"`
Destination ModuleField `json:"destination"`
}
ModuleFieldMappingSetFindType int
)
// Find looks up a origin or destination mapping
func (list *ModuleFieldMappingSet) FindByName(name string, findType ModuleFieldMappingSetFindType) (*ModuleFieldMapping, error) {
for _, mfm := range *list {
switch findType {
case ModuleFieldMappingSetFindTypeOrigin:
if mfm.Origin.Name == name {
return mfm, nil
}
case ModuleFieldMappingSetFindTypeDestination:
if mfm.Destination.Name == name {
return mfm, nil
}
}
}
return nil, nil
}
func (list *ModuleFieldMappingSet) Scan(src any) error { return sql.ParseJSON(src, list) }
func (list ModuleFieldMappingSet) Value() (driver.Value, error) { return json.Marshal(list) }