From 4a4eb2fd992c6164f0746d87515e6a8700845fc3 Mon Sep 17 00:00:00 2001 From: RPJosh Date: Mon, 15 Apr 2024 17:29:34 +0200 Subject: [PATCH] Add flag for default value --- structt/tags.go | 11 +++++++++++ structt/tags_test.go | 1 + 2 files changed, 12 insertions(+) diff --git a/structt/tags.go b/structt/tags.go index f7994bd..484d26e 100644 --- a/structt/tags.go +++ b/structt/tags.go @@ -41,6 +41,9 @@ type ColumnTag struct { // Mariadb: weather this field has the property "auto_increment" AutoIncrement bool + + // Weather this column has a default value + HasDefaultValue bool } // Identifier of the struct tag for "MetadataTag" @@ -81,6 +84,9 @@ func GetColumnTag(col *ddl.Column) *ColumnTag { rtc.AutoIncrement = mariaDb.AutoIncrement } + // Add some boolean flags + rtc.HasDefaultValue = col.DefaultValue.Valid + return rtc } @@ -104,6 +110,9 @@ func (c *ColumnTag) ToTag() (rtc string) { if c.ForeignKeyReference != "" { rtc += ",ForeignKey:" + c.ForeignKeyReference } + if c.HasDefaultValue { + rtc += ",DefaultValue" + } return rtc } @@ -122,6 +131,8 @@ func FromColumnTag(tag string) *ColumnTag { rtc.AutoIncrement = true case "PrimaryKey": rtc.IsPrimaryKey = true + case "DefaultValue": + rtc.HasDefaultValue = true } // Key-value pairs diff --git a/structt/tags_test.go b/structt/tags_test.go index 0ab3e98..3ab327f 100644 --- a/structt/tags_test.go +++ b/structt/tags_test.go @@ -32,6 +32,7 @@ func TestColumnTagTransformPositive(t *testing.T) { ForeignKeyReference: "workout.users.id", PointedKeyReference: "hello", AutoIncrement: true, + HasDefaultValue: true, } // Transform to string