Skip to content

Commit

Permalink
Merge pull request #393 from k1LoW/constraints
Browse files Browse the repository at this point in the history
Change columns key to constants.
  • Loading branch information
k1LoW authored Dec 6, 2022
2 parents ec726a6 + 6788925 commit 5c97347
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 44 deletions.
28 changes: 14 additions & 14 deletions output/md/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,13 @@ func (m *Md) makeTableTemplateData(t *schema.Table) map[string]interface{} {
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, true, "Type")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, true, "Default")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, true, "Nullable")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn("ExtraDef", hideColumns), "Extra Definition")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn("Occurrences", hideColumns), "Occurrences")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn("Percents", hideColumns), "Percents")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn("Children", hideColumns), "Children")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn("Parents", hideColumns), "Parents")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn("Comment", hideColumns), "Comment")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn("Labels", hideColumns), "Labels")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn(schema.ColumnExtraDef, hideColumns), "Extra Definition")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn(schema.ColumnOccurrences, hideColumns), "Occurrences")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn(schema.ColumnPercents, hideColumns), "Percents")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn(schema.ColumnChildren, hideColumns), "Children")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn(schema.ColumnParents, hideColumns), "Parents")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn(schema.ColumnComment, hideColumns), "Comment")
m.adjustColumnHeader(&columnsHeader, &columnsHeaderLine, t.ShowColumn(schema.ColumnLabels, hideColumns), "Labels")

columnsData = append(columnsData, columnsHeader, columnsHeaderLine)

Expand Down Expand Up @@ -565,13 +565,13 @@ func (m *Md) makeTableTemplateData(t *schema.Table) map[string]interface{} {
c.Default.String,
fmt.Sprintf("%v", c.Nullable),
}
adjustData(&data, t.ShowColumn("ExtraDef", hideColumns), mdEscRep.Replace(c.ExtraDef))
adjustData(&data, t.ShowColumn("Occurrences", hideColumns), fmt.Sprint(c.Occurrences.Int32))
adjustData(&data, t.ShowColumn("Percents", hideColumns), fmt.Sprintf("%.1f", c.Percents.Float64))
adjustData(&data, t.ShowColumn("Children", hideColumns), strings.Join(childRelations, " "))
adjustData(&data, t.ShowColumn("Parents", hideColumns), strings.Join(parentRelations, " "))
adjustData(&data, t.ShowColumn("Comment", hideColumns), c.Comment)
adjustData(&data, t.ShowColumn("Labels", hideColumns), output.LabelJoin(c.Labels))
adjustData(&data, t.ShowColumn(schema.ColumnExtraDef, hideColumns), mdEscRep.Replace(c.ExtraDef))
adjustData(&data, t.ShowColumn(schema.ColumnOccurrences, hideColumns), fmt.Sprint(c.Occurrences.Int32))
adjustData(&data, t.ShowColumn(schema.ColumnPercents, hideColumns), fmt.Sprintf("%.1f", c.Percents.Float64))
adjustData(&data, t.ShowColumn(schema.ColumnChildren, hideColumns), strings.Join(childRelations, " "))
adjustData(&data, t.ShowColumn(schema.ColumnParents, hideColumns), strings.Join(parentRelations, " "))
adjustData(&data, t.ShowColumn(schema.ColumnComment, hideColumns), c.Comment)
adjustData(&data, t.ShowColumn(schema.ColumnLabels, hideColumns), output.LabelJoin(c.Labels))
columnsData = append(columnsData, data)
}

Expand Down
33 changes: 12 additions & 21 deletions output/xlsx/xlsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ import (
"github.com/pkg/errors"
)

const (
hide_column_extra_def = "ExtraDef"
hide_column_occurrences = "Occurrences"
hide_column_percents = "Percents"
hide_column_children = "Children"
hide_column_parents = "Parents"
hide_column_comment = "Comment"
)

// Xlsx struct
type Xlsx struct {
config *config.Config
Expand Down Expand Up @@ -181,12 +172,12 @@ func (x *Xlsx) createTableSheet(w *excl.Workbook, t *schema.Table) (e error) {
x.config.MergedDict.Lookup("Nullable"),
}
hideColumns := x.config.Format.HideColumnsWithoutValues
x.adjustColumnHeader(&columnValues, t.ShowColumn(hide_column_extra_def, hideColumns), "Extra Definition")
x.adjustColumnHeader(&columnValues, t.ShowColumn(hide_column_occurrences, hideColumns), "Occurrences")
x.adjustColumnHeader(&columnValues, t.ShowColumn(hide_column_percents, hideColumns), "Percents")
x.adjustColumnHeader(&columnValues, t.ShowColumn(hide_column_children, hideColumns), "Children")
x.adjustColumnHeader(&columnValues, t.ShowColumn(hide_column_parents, hideColumns), "Parents")
x.adjustColumnHeader(&columnValues, t.ShowColumn(hide_column_comment, hideColumns), "Comment")
x.adjustColumnHeader(&columnValues, t.ShowColumn(schema.ColumnExtraDef, hideColumns), "Extra Definition")
x.adjustColumnHeader(&columnValues, t.ShowColumn(schema.ColumnOccurrences, hideColumns), "Occurrences")
x.adjustColumnHeader(&columnValues, t.ShowColumn(schema.ColumnPercents, hideColumns), "Percents")
x.adjustColumnHeader(&columnValues, t.ShowColumn(schema.ColumnChildren, hideColumns), "Children")
x.adjustColumnHeader(&columnValues, t.ShowColumn(schema.ColumnParents, hideColumns), "Parents")
x.adjustColumnHeader(&columnValues, t.ShowColumn(schema.ColumnComment, hideColumns), "Comment")
setHeader(sheet, 5, columnValues)
r := 6
for i, c := range t.Columns {
Expand All @@ -195,20 +186,20 @@ func (x *Xlsx) createTableSheet(w *excl.Workbook, t *schema.Table) (e error) {
setStringWithBorder(sheet, r+i, 3, c.Default.String)
setStringWithBorder(sheet, r+i, 4, fmt.Sprintf("%v", c.Nullable))
ci := 5
ci = adjustData(t.ShowColumn(hide_column_extra_def, hideColumns), sheet, r+i, ci, fmt.Sprintf("%v", c.ExtraDef))
ci = adjustData(t.ShowColumn(hide_column_occurrences, hideColumns), sheet, r+i, ci, fmt.Sprintf("%d", c.Occurrences.Int32))
ci = adjustData(t.ShowColumn(hide_column_percents, hideColumns), sheet, r+i, ci, fmt.Sprintf("%.1f", c.Percents.Float64))
ci = adjustData(t.ShowColumn(schema.ColumnExtraDef, hideColumns), sheet, r+i, ci, fmt.Sprintf("%v", c.ExtraDef))
ci = adjustData(t.ShowColumn(schema.ColumnOccurrences, hideColumns), sheet, r+i, ci, fmt.Sprintf("%d", c.Occurrences.Int32))
ci = adjustData(t.ShowColumn(schema.ColumnPercents, hideColumns), sheet, r+i, ci, fmt.Sprintf("%.1f", c.Percents.Float64))
children := []string{}
for _, child := range c.ChildRelations {
children = append(children, child.Table.Name)
}
ci = adjustData(t.ShowColumn(hide_column_children, hideColumns), sheet, r+i, ci, strings.Join(children, "\n"))
ci = adjustData(t.ShowColumn(schema.ColumnChildren, hideColumns), sheet, r+i, ci, strings.Join(children, "\n"))
parents := []string{}
for _, parent := range c.ParentRelations {
parents = append(parents, parent.ParentTable.Name)
}
ci = adjustData(t.ShowColumn(hide_column_parents, hideColumns), sheet, r+i, ci, strings.Join(parents, "\n"))
ci = adjustData(t.ShowColumn(hide_column_comment, hideColumns), sheet, r+i, ci, c.Comment) //nolint
ci = adjustData(t.ShowColumn(schema.ColumnParents, hideColumns), sheet, r+i, ci, strings.Join(parents, "\n"))
ci = adjustData(t.ShowColumn(schema.ColumnComment, hideColumns), sheet, r+i, ci, c.Comment) //nolint
}
r = r + len(t.Columns)

Expand Down
28 changes: 19 additions & 9 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ const (
TypeFK = "FOREIGN KEY"
)

var DefaultHideColumns = []string{"ExtraDef", "Occurrences", "Percents", "Labels"}
var HideableColumns = []string{"ExtraDef", "Occurrences", "Percents", "Children", "Parents", "Comment", "Labels"}
const (
ColumnExtraDef = "ExtraDef"
ColumnOccurrences = "Occurrences"
ColumnPercents = "Percents"
ColumnChildren = "Children"
ColumnParents = "Parents"
ColumnComment = "Comment"
ColumnLabels = "Labels"
)

var DefaultHideColumns = []string{ColumnExtraDef, ColumnOccurrences, ColumnPercents, ColumnLabels}
var HideableColumns = []string{ColumnExtraDef, ColumnOccurrences, ColumnPercents, ColumnChildren, ColumnParents, ColumnComment, ColumnLabels}

type Label struct {
Name string
Expand Down Expand Up @@ -256,31 +266,31 @@ func (t *Table) FindConstrainsByColumnName(name string) []*Constraint {
func (t *Table) hasColumnWithValues(name string) bool {
for _, c := range t.Columns {
switch name {
case "ExtraDef":
case ColumnExtraDef:
if c.ExtraDef != "" {
return true
}
case "Occurrences":
case ColumnOccurrences:
if c.Occurrences.Valid {
return true
}
case "Percents":
case ColumnPercents:
if c.Percents.Valid {
return true
}
case "Children":
case ColumnChildren:
if len(c.ChildRelations) > 0 {
return true
}
case "Parents":
case ColumnParents:
if len(c.ParentRelations) > 0 {
return true
}
case "Comment":
case ColumnComment:
if c.Comment != "" {
return true
}
case "Labels":
case ColumnLabels:
if len(c.Labels) > 0 {
return true
}
Expand Down

0 comments on commit 5c97347

Please sign in to comment.