-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.go
50 lines (46 loc) · 1.6 KB
/
configuration.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
package morph
// Configuration represents the configuration used to construct
// the table and column mappings.
type Configuration struct {
Tables []TableConfiguration `json:"tables" yaml:"tables"`
}
// AsMetadata converts the configuration to metadata mappings.
func (c Configuration) AsMetadata() []Table {
var tables []Table
for _, t := range c.Tables {
var table Table
table.SetTypeName(t.TypeName)
table.SetName(t.Name)
table.SetAlias(t.Alias)
for _, c := range t.Columns {
var column Column
column.SetField(c.Field)
column.SetName(c.Name)
column.SetFieldType(c.FieldType)
column.SetStrategy(c.FieldStrategy)
column.SetPrimaryKey(c.PrimaryKey)
if err := table.AddColumn(column); err != nil {
continue
}
}
tables = append(tables, table)
}
return tables
}
// TableConfiguration represents the configuration used to construct
// a single table mapping.
type TableConfiguration struct {
TypeName string `json:"typeName" yaml:"typeName"`
Name string `json:"name" yaml:"name"`
Alias string `json:"alias" yaml:"alias"`
Columns []ColumnConfiguration `json:"columns" yaml:"columns"`
}
// ColumnConfiguration represents the configuration used to construct
// a single column mapping.
type ColumnConfiguration struct {
Name string `json:"name" yaml:"name"`
Field string `json:"field" yaml:"field"`
FieldType string `json:"fieldType" yaml:"fieldType"`
FieldStrategy FieldStrategy `json:"fieldStrategy" yaml:"fieldStrategy"`
PrimaryKey bool `json:"primaryKey" yaml:"primaryKey"`
}