From 30e148f0e35fbc20aaaf910a3953a943214277c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Dulai?= Date: Sat, 6 Jun 2026 10:34:47 +0200 Subject: [PATCH] Multi struct test case --- schema/column.go | 7 +++++-- test/main_test.go | 7 +++++++ test/schema_test.go | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/schema/column.go b/schema/column.go index cf08e58..4574d24 100644 --- a/schema/column.go +++ b/schema/column.go @@ -40,11 +40,14 @@ func determineModifiers(tag reflect.StructTag) map[string]string { func (c *Column) GetDDL() (string, error) { var ddlBuilder strings.Builder - ddlBuilder.WriteString(c.Name + " " + c.Type) + ddlBuilder.WriteString(c.Name) + ddlBuilder.WriteString(" ") + ddlBuilder.WriteString(c.Type) inlineMods := c.inlineModifiers() for _, mod := range inlineMods { - ddlBuilder.WriteString(" " + mod) + ddlBuilder.WriteString(" ") + ddlBuilder.WriteString(mod) } return ddlBuilder.String(), nil diff --git a/test/main_test.go b/test/main_test.go index 6d36dba..4ee35e5 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -56,6 +56,13 @@ type TestWithTime struct { TimeField int64 `sql:"nn"` } +type TestWithJsonStructTag struct { + ID int `json:"id" sql:"pk"` + Int64Field int64 `json:"int64Field" sql:"nn"` + IntField int `json:"intField" sql:"nn"` + StringField string `json:"stringField" sql:"nn"` +} + func TestMain(m *testing.M) { log.SetupLogs("Info") diff --git a/test/schema_test.go b/test/schema_test.go index 1b6ab35..e4a5eb1 100644 --- a/test/schema_test.go +++ b/test/schema_test.go @@ -113,3 +113,23 @@ func TestParseCompositeFk(t *testing.T) { t.Fail() } } + +func TestParseStructWithJsonTag(t *testing.T) { + // GIVEN + orm := simpleorm.NewORM(TestWithJsonStructTag{}) + // WHEN + ddl, err := orm.CreateSchema() + // THEN + if err != nil { + log.LogError("Failed to parse schema! %s", err) + t.Fail() + } + + expectedDdl := "CREATE TABLE IF NOT EXISTS TEST_WITH_JSON_STRUCT_TAG (ID INTEGER, INT64_FIELD BIGINT NOT NULL, INT_FIELD INTEGER NOT NULL, STRING_FIELD TEXT NOT NULL, CONSTRAINT pk_test_with_json_struct_tag PRIMARY KEY(ID));" + if ddl != expectedDdl { + log.LogError("Incorrect DDL.\nExpected\n%s\nActual\n%s", expectedDdl, ddl) + log.LogError("\nExpected size: %s\nActual size: %s", strconv.Itoa(len(expectedDdl)), strconv.Itoa(len(ddl))) + t.Fail() + } + log.LogInfo("Test finished!") +}