Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model generator now can take optional gotype 3rd arg #68

Merged
merged 6 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion soda/cmd/generate/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ func newAttribute(base string, model *model) attribute {
model.Imports = append(model.Imports, "github.com/gobuffalo/uuid")
}

got := colType(col[1])
if len(col) > 2 {
got = col[2]
}
a := attribute{
Name: inflect.Name(col[0]),
OriginalType: col[1],
GoType: colType(col[1]),
GoType: got,
Nullable: nullable,
}

Expand Down
10 changes: 9 additions & 1 deletion soda/cmd/generate/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func Test_Attribute_String(t *testing.T) {
}

func Test_newAttribute(t *testing.T) {
r := require.New(t)
cases := []struct {
AttributeInput string
ResultType string
Expand Down Expand Up @@ -91,10 +90,19 @@ func Test_newAttribute(t *testing.T) {
AttributeInput: "raw:[]byte",
ResultType: "[]byte",
},
{
AttributeInput: "age:int",
ResultType: "int",
},
{
AttributeInput: "age:int:int64",
ResultType: "int64",
},
}

for index, tcase := range cases {
t.Run(fmt.Sprintf("%d-%s", index, tcase.AttributeInput), func(tt *testing.T) {
r := require.New(tt)
model := newModel("car")
a := newAttribute(tcase.AttributeInput, &model)

Expand Down