-
Notifications
You must be signed in to change notification settings - Fork 9
/
mapping.go
47 lines (40 loc) · 1.32 KB
/
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
47
package dsunit
import "github.com/viant/dsunit/url"
//Mapping represents mapping
type Mapping struct {
*url.Resource
*MappingTable
Name string `required:"true" description:"mapping name (i.e view name)"`
}
//MappingTable represents a table mapping, mapping allow to route data defined in only one table to many tables.
type MappingTable struct {
Table string `required:"true"`
Columns []*MappingColumn `required:"true"`
Associations []*MappingTable
}
//MappingColumn represents column with its source definition.
type MappingColumn struct {
Name string `required:"true" description:"column name"`
DefaultValue string
FromColumn string `description:"if specified it defined value source for this column"`
Required bool `description:"table record will be mapped if values for all required columns are present"`
Unique bool `description:"flag key/s that are unique"`
}
//Tables returns tables of this mapping
func (m *Mapping) Tables() []string {
var result = make([]string, 0)
addTables(&result, m.MappingTable)
return result
}
func addTables(tables *[]string, mapping *MappingTable) {
if mapping == nil {
return
}
*tables = append(*tables, mapping.Table)
if len(mapping.Associations) == 0 {
return
}
for _, association := range mapping.Associations {
addTables(tables, association)
}
}