Skip to content

fix: Nullable Primitives #32

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

Open
wants to merge 2 commits into
base: main
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
51 changes: 38 additions & 13 deletions internal/core/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ func jdbcSet(t ktType, idx int, name string) string {
if t.IsUUID() {
return fmt.Sprintf("stmt.setObject(%d, %s)", idx, name)
}
return fmt.Sprintf("stmt.set%s(%d, %s)", t.Name, idx, name)
if t.IsNull && t.PrimitiveType != "" {
return fmt.Sprintf("if (%[3]s != null) stmt.set%[1]s(%[2]d, %[3]s) else stmt.setNull(%[2]d, Types.%[4]s)", t.Name, idx, name, t.PrimitiveType)
} else {
return fmt.Sprintf("stmt.set%s(%d, %s)", t.Name, idx, name)
}
}

type Params struct {
Expand Down Expand Up @@ -320,12 +324,13 @@ func BuildDataClasses(conf Config, req *plugin.GenerateRequest) []Struct {
}

type ktType struct {
Name string
IsEnum bool
IsArray bool
IsNull bool
DataType string
Engine string
Name string
IsEnum bool
IsArray bool
IsNull bool
PrimitiveType string
DataType string
Engine string
}

func (t ktType) String() string {
Expand Down Expand Up @@ -374,12 +379,13 @@ func (t ktType) IsBigDecimal() bool {
func makeType(req *plugin.GenerateRequest, col *plugin.Column) ktType {
typ, isEnum := ktInnerType(req, col)
return ktType{
Name: typ,
IsEnum: isEnum,
IsArray: col.IsArray,
IsNull: !col.NotNull,
DataType: sdk.DataType(col.Type),
Engine: req.Settings.Engine,
Name: typ,
IsEnum: isEnum,
IsArray: col.IsArray,
IsNull: !col.NotNull,
PrimitiveType: ktPrimitiveType(typ),
DataType: sdk.DataType(col.Type),
Engine: req.Settings.Engine,
}
}

Expand All @@ -395,6 +401,25 @@ func ktInnerType(req *plugin.GenerateRequest, col *plugin.Column) (string, bool)
}
}

func ktPrimitiveType(t string) string {
switch t {
case "Int":
return "INTEGER"
case "Double":
return "DOUBLE"
case "Long":
return "BIGINT"
case "Short":
return "SMALLINT"
case "Float":
return "REAL"
case "Boolean":
return "BOOLEAN"
default:
return ""
}
}

type goColumn struct {
id int
*plugin.Column
Expand Down