2022-11-03 13:54:49 +00:00
|
|
|
package d2target
|
|
|
|
|
|
2022-12-20 05:02:50 +00:00
|
|
|
const (
|
2022-12-29 07:15:16 +00:00
|
|
|
NamePadding = 10
|
|
|
|
|
TypePadding = 20
|
2023-02-06 08:42:28 +00:00
|
|
|
HeaderPadding = 10
|
|
|
|
|
|
|
|
|
|
// Setting table font size sets it for columns
|
|
|
|
|
// The header needs to be a little larger for visual hierarchy
|
|
|
|
|
HeaderFontAdd = 4
|
2022-12-20 05:02:50 +00:00
|
|
|
)
|
|
|
|
|
|
2022-11-03 13:54:49 +00:00
|
|
|
type SQLTable struct {
|
|
|
|
|
Columns []SQLColumn `json:"columns"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SQLColumn struct {
|
2022-12-20 01:14:39 +00:00
|
|
|
Name Text `json:"name"`
|
|
|
|
|
Type Text `json:"type"`
|
2022-11-03 13:54:49 +00:00
|
|
|
Constraint string `json:"constraint"`
|
|
|
|
|
Reference string `json:"reference"`
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 08:42:28 +00:00
|
|
|
func (c SQLColumn) Texts(fontSize int) []*MText {
|
2022-12-23 08:29:03 +00:00
|
|
|
return []*MText{
|
|
|
|
|
{
|
|
|
|
|
Text: c.Name.Label,
|
2023-02-06 08:42:28 +00:00
|
|
|
FontSize: fontSize,
|
2022-12-23 08:29:03 +00:00
|
|
|
IsBold: false,
|
|
|
|
|
IsItalic: false,
|
|
|
|
|
Shape: "sql_table",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Text: c.Type.Label,
|
2023-02-06 08:42:28 +00:00
|
|
|
FontSize: fontSize,
|
2022-12-23 08:29:03 +00:00
|
|
|
IsBold: false,
|
|
|
|
|
IsItalic: false,
|
|
|
|
|
Shape: "sql_table",
|
|
|
|
|
},
|
2022-11-03 13:54:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-12-22 19:06:57 +00:00
|
|
|
|
|
|
|
|
func (c SQLColumn) ConstraintAbbr() string {
|
|
|
|
|
switch c.Constraint {
|
|
|
|
|
case "primary_key":
|
|
|
|
|
return "PK"
|
|
|
|
|
case "foreign_key":
|
|
|
|
|
return "FK"
|
|
|
|
|
case "unique":
|
|
|
|
|
return "UNQ"
|
|
|
|
|
default:
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
}
|