+5
-2
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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!")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user