-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
82 lines (68 loc) · 1.51 KB
/
config.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
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"os"
"time"
"gopkg.in/yaml.v3"
)
type Config struct {
Tables []Table `yaml:"tables"`
BatchSize int `yaml:"batch_size"`
}
func (c *Config) Parse(path string) error {
b, err := os.ReadFile(path)
if err != nil {
return err
}
return yaml.Unmarshal(b, c)
}
func (c *Config) Save(path string) error {
b, err := yaml.Marshal(&c)
if err != nil {
return err
}
return os.WriteFile(path, b, 0644)
}
type Table struct {
Source string `yaml:"source"`
Destination string `yaml:"destination"`
Indexes []Index `yaml:"indexes"`
Columns []Column `yaml:"columns"`
Cursor Cursor `yaml:"cursor"`
}
func (t *Table) GetSourceColumns() []string {
names := []string{}
for _, column := range t.Columns {
names = append(names, column.Source)
}
return names
}
func (t *Table) GetDestinationColumns() []string {
names := []string{}
for _, column := range t.Columns {
names = append(names, column.Destination)
}
return names
}
func (t *Table) GetPrimaryKey() []string {
names := []string{}
for _, column := range t.Columns {
if column.Primary {
names = append(names, column.Destination)
}
}
return names
}
type Column struct {
Source string `yaml:"source"`
Destination string `yaml:"destination"`
Type string `yaml:"type"`
Primary bool `yaml:"primary"`
}
type Cursor struct {
Column string `yaml:"column"`
LastSync time.Time `yaml:"last_sync"`
}
type Index struct {
Name string `yaml:"name"`
Columns []string `yaml:"columns"`
}