-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests; split up logic of diagram creation
- Loading branch information
Showing
9 changed files
with
356 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package diagram | ||
|
||
import ( | ||
"github.com/KarnerTh/mermerd/config" | ||
"github.com/KarnerTh/mermerd/database" | ||
) | ||
|
||
func getRelation(constraint database.ConstraintResult) ErdRelationType { | ||
if constraint.IsPrimary && !constraint.HasMultiplePK { | ||
return relationOneToOne | ||
} else { | ||
return relationManyToOne | ||
} | ||
} | ||
|
||
func tableNameInSlice(slice []ErdTableData, tableName string) bool { | ||
for _, sliceItem := range slice { | ||
if sliceItem.Name == tableName { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
func getAttributeKey(column database.ColumnResult) ErdAttributeKey { | ||
if column.IsPrimary { | ||
return primaryKey | ||
} | ||
|
||
if column.IsForeign { | ||
return foreignKey | ||
} | ||
|
||
return none | ||
} | ||
|
||
func getColumnData(config config.MermerdConfig, column database.ColumnResult) ErdColumnData { | ||
attributeKey := getAttributeKey(column) | ||
if config.OmitAttributeKeys() { | ||
attributeKey = none | ||
} | ||
|
||
var enumValues string | ||
if config.ShowEnumValues() { | ||
enumValues = column.EnumValues | ||
} | ||
|
||
return ErdColumnData{ | ||
Name: column.Name, | ||
DataType: column.DataType, | ||
EnumValues: enumValues, | ||
AttributeKey: attributeKey, | ||
} | ||
} | ||
|
||
func shouldSkipConstraint(config config.MermerdConfig, tables []ErdTableData, constraint database.ConstraintResult) bool { | ||
if config.ShowAllConstraints() { | ||
return false | ||
} | ||
|
||
// if config for all constraints is not set, only show constraints of selected tables | ||
return !(tableNameInSlice(tables, constraint.PkTable) && tableNameInSlice(tables, constraint.FkTable)) | ||
} | ||
|
||
func getConstraintData(config config.MermerdConfig, constraint database.ConstraintResult) ErdConstraintData { | ||
constraintLabel := constraint.ColumnName | ||
if config.OmitConstraintLabels() { | ||
constraintLabel = "" | ||
} | ||
|
||
return ErdConstraintData{ | ||
PkTableName: constraint.PkTable, | ||
FkTableName: constraint.FkTable, | ||
Relation: getRelation(constraint), | ||
ConstraintLabel: constraintLabel, | ||
} | ||
} |
Oops, something went wrong.