d2/d2target/sqltable.go

50 lines
821 B
Go
Raw Normal View History

package d2target
2022-12-20 05:02:50 +00:00
const (
NamePadding = 10
TypePadding = 20
)
type SQLTable struct {
Columns []SQLColumn `json:"columns"`
}
type SQLColumn struct {
Name Text `json:"name"`
Type Text `json:"type"`
Constraint string `json:"constraint"`
Reference string `json:"reference"`
}
2022-12-23 08:29:03 +00:00
func (c SQLColumn) Texts() []*MText {
return []*MText{
{
Text: c.Name.Label,
FontSize: c.Name.FontSize,
IsBold: false,
IsItalic: false,
Shape: "sql_table",
},
{
Text: c.Type.Label,
FontSize: c.Type.FontSize,
IsBold: false,
IsItalic: false,
Shape: "sql_table",
},
}
}
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 ""
}
}