Skip to content

Commit

Permalink
Fix Column Marshal/Unmarchal JSON/YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Dec 27, 2020
1 parent 67e0875 commit 6037ce3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions schema/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (c Column) MarshalJSON() ([]byte, error) {
Type string `json:"type"`
Nullable bool `json:"nullable"`
Default string `json:"default"`
ExtraDef string `json:"extra_def,omitempty"`
Comment string `json:"comment"`
ParentRelations []*Relation `json:"-"`
ChildRelations []*Relation `json:"-"`
Expand All @@ -100,6 +101,7 @@ func (c Column) MarshalJSON() ([]byte, error) {
Nullable: c.Nullable,
Default: c.Default.String,
Comment: c.Comment,
ExtraDef: c.ExtraDef,
ParentRelations: c.ParentRelations,
ChildRelations: c.ChildRelations,
})
Expand All @@ -110,6 +112,7 @@ func (c Column) MarshalJSON() ([]byte, error) {
Nullable bool `json:"nullable"`
Default *string `json:"default"`
Comment string `json:"comment"`
ExtraDef string `json:"extra_def,omitempty"`
ParentRelations []*Relation `json:"-"`
ChildRelations []*Relation `json:"-"`
}{
Expand All @@ -118,6 +121,7 @@ func (c Column) MarshalJSON() ([]byte, error) {
Nullable: c.Nullable,
Default: nil,
Comment: c.Comment,
ExtraDef: c.ExtraDef,
ParentRelations: c.ParentRelations,
ChildRelations: c.ChildRelations,
})
Expand Down Expand Up @@ -159,6 +163,7 @@ func (c *Column) UnmarshalJSON(data []byte) error {
Nullable bool `json:"nullable"`
Default *string `json:"default"`
Comment string `json:"comment"`
ExtraDef string `json:"extra_def,omitempty"`
ParentRelations []*Relation `json:"-"`
ChildRelations []*Relation `json:"-"`
}{}
Expand All @@ -176,6 +181,7 @@ func (c *Column) UnmarshalJSON(data []byte) error {
c.Default.Valid = false
c.Default.String = ""
}
c.ExtraDef = s.ExtraDef
c.Comment = s.Comment
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions schema/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func (c Column) MarshalYAML() ([]byte, error) {
Type string `yaml:"type"`
Nullable bool `yaml:"nullable"`
Default string `yaml:"default"`
ExtraDef string `json:"extraDef,omitempty"`
Comment string `yaml:"comment"`
ParentRelations []*Relation `yaml:"-"`
ChildRelations []*Relation `yaml:"-"`
Expand All @@ -19,6 +20,7 @@ func (c Column) MarshalYAML() ([]byte, error) {
Nullable: c.Nullable,
Default: c.Default.String,
Comment: c.Comment,
ExtraDef: c.ExtraDef,
ParentRelations: c.ParentRelations,
ChildRelations: c.ChildRelations,
})
Expand All @@ -28,6 +30,7 @@ func (c Column) MarshalYAML() ([]byte, error) {
Type string `yaml:"type"`
Nullable bool `yaml:"nullable"`
Default *string `yaml:"default"`
ExtraDef string `json:"extraDef,omitempty"`
Comment string `yaml:"comment"`
ParentRelations []*Relation `yaml:"-"`
ChildRelations []*Relation `yaml:"-"`
Expand All @@ -36,6 +39,7 @@ func (c Column) MarshalYAML() ([]byte, error) {
Type: c.Type,
Nullable: c.Nullable,
Default: nil,
ExtraDef: c.ExtraDef,
Comment: c.Comment,
ParentRelations: c.ParentRelations,
ChildRelations: c.ChildRelations,
Expand Down Expand Up @@ -78,6 +82,7 @@ func (c *Column) UnmarshalYAML(data []byte) error {
Nullable bool `yaml:"nullable"`
Default *string `yaml:"default"`
Comment string `yaml:"comment"`
ExtraDef string `json:"extraDef,omitempty"`
ParentRelations []*Relation `yaml:"-"`
ChildRelations []*Relation `yaml:"-"`
}{}
Expand All @@ -96,6 +101,7 @@ func (c *Column) UnmarshalYAML(data []byte) error {
c.Default.Valid = false
c.Default.String = ""
}
c.ExtraDef = s.ExtraDef
c.Comment = s.Comment
return nil
}
Expand Down

0 comments on commit 6037ce3

Please sign in to comment.