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

fix model generator panic when field type as user-defined #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func getType(fieldDescriptor fieldDescriptor) (goType string, fieldClass string,
fieldClass = "StringField"
case "array":
// TODO: Switch to specific type instead of interface.
goType = "[]interface{}"
fieldClass = "ArrayField"
goType = "string"
fieldClass = "StringField"
case "timestamp":
if !timeAsString {
goType = "time.Time"
Expand Down Expand Up @@ -132,6 +132,9 @@ func getType(fieldDescriptor fieldDescriptor) (goType string, fieldClass string,
goType = "string"
fieldClass = "StringField"
}
case "user-defined":
goType = "string"
fieldClass = "StringField"
default:
err = fmt.Errorf("unknown field type %s", fieldDescriptor.Type)
return
Expand Down Expand Up @@ -247,10 +250,6 @@ func Generate(driverName string, exampleDataSourceName string) (string, error) {
code += "\tsqlingo.BooleanField\n"
code += "}\n\n"

code += "type arrayField interface {\n"
code += "\tsqlingo.ArrayField\n"
code += "}\n\n"

code += "type dateField interface {\n"
code += "\tsqlingo.DateField\n"
code += "}\n\n"
Expand Down Expand Up @@ -435,5 +434,6 @@ func generateTable(schemaFetcher schemaFetcher, tableName string, forceCases []s
// replaceTypeSpace : To compatible some types contains spaces in postgresql
// like [character varying, timestamp without time zone, timestamp with time zone]
func replaceTypeSpace(typename string) string {
return strings.ReplaceAll(typename, " ", "_")
typename = strings.ReplaceAll(typename, " ", "_")
return strings.ReplaceAll(typename, "-", "_")
}
Loading