Add flag for default value

main v0.1.1
Jonas Letzbor 2024-04-15 17:29:34 +02:00
parent e6f9d11f42
commit 4a4eb2fd99
Signed by: RPJosh
GPG Key ID: 43ACB900522EA740
2 changed files with 12 additions and 0 deletions

View File

@ -41,6 +41,9 @@ type ColumnTag struct {
// Mariadb: weather this field has the property "auto_increment" // Mariadb: weather this field has the property "auto_increment"
AutoIncrement bool AutoIncrement bool
// Weather this column has a default value
HasDefaultValue bool
} }
// Identifier of the struct tag for "MetadataTag" // Identifier of the struct tag for "MetadataTag"
@ -81,6 +84,9 @@ func GetColumnTag(col *ddl.Column) *ColumnTag {
rtc.AutoIncrement = mariaDb.AutoIncrement rtc.AutoIncrement = mariaDb.AutoIncrement
} }
// Add some boolean flags
rtc.HasDefaultValue = col.DefaultValue.Valid
return rtc return rtc
} }
@ -104,6 +110,9 @@ func (c *ColumnTag) ToTag() (rtc string) {
if c.ForeignKeyReference != "" { if c.ForeignKeyReference != "" {
rtc += ",ForeignKey:" + c.ForeignKeyReference rtc += ",ForeignKey:" + c.ForeignKeyReference
} }
if c.HasDefaultValue {
rtc += ",DefaultValue"
}
return rtc return rtc
} }
@ -122,6 +131,8 @@ func FromColumnTag(tag string) *ColumnTag {
rtc.AutoIncrement = true rtc.AutoIncrement = true
case "PrimaryKey": case "PrimaryKey":
rtc.IsPrimaryKey = true rtc.IsPrimaryKey = true
case "DefaultValue":
rtc.HasDefaultValue = true
} }
// Key-value pairs // Key-value pairs

View File

@ -32,6 +32,7 @@ func TestColumnTagTransformPositive(t *testing.T) {
ForeignKeyReference: "workout.users.id", ForeignKeyReference: "workout.users.id",
PointedKeyReference: "hello", PointedKeyReference: "hello",
AutoIncrement: true, AutoIncrement: true,
HasDefaultValue: true,
} }
// Transform to string // Transform to string