package d2target
import "strings"
const (
NamePadding = 10
TypePadding = 20
ConstraintPadding = 20
HeaderPadding = 10
HeaderFontAdd = 4
)
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"`
}
func (c SQLColumn ) Texts (fontSize int ) []*MText {
return []*MText {
{
Text : c .Name .Label ,
FontSize : fontSize ,
IsBold : false ,
IsItalic : false ,
Shape : "sql_table" ,
},
{
Text : c .Type .Label ,
FontSize : fontSize ,
IsBold : false ,
IsItalic : false ,
Shape : "sql_table" ,
},
{
Text : c .ConstraintAbbr (),
FontSize : fontSize ,
IsBold : false ,
IsItalic : false ,
Shape : "sql_table" ,
},
}
}
func (c SQLColumn ) ConstraintAbbr () string {
constraints := make ([]string , len (c .Constraint ))
for i , constraint := range c .Constraint {
switch constraint {
case "primary_key" :
constraint = "PK"
case "foreign_key" :
constraint = "FK"
case "unique" :
constraint = "UNQ"
}
constraints [i ] = constraint
}
return strings .Join (constraints , ", " )
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .