Skip to content

Add all Go types for the code generator of the sqlite engine #1001

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

Merged
merged 2 commits into from
May 4, 2021
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
41 changes: 36 additions & 5 deletions internal/codegen/golang/sqlite_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,40 @@ import (
)

func sqliteType(r *compiler.Result, col *compiler.Column, settings config.CombinedSettings) string {
dt := col.DataType
dt := strings.ToLower(col.DataType)
notNull := col.NotNull || col.IsArray

switch dt {

case "integer":
case "int", "integer", "tinyint", "smallint", "mediumint", "bigint", "unsignedbigint", "int2", "int8", "numeric", "decimal":
if notNull {
return "int32"
return "int64"
}
return "sql.NullInt32"
return "sql.NullInt64"

case "blob":
if notNull {
return "[]uint8"
}
return "*[]uint8"

case "real", "double", "doubleprecision", "float":
if notNull {
return "float64"
}
return "sql.NullFloat64"

case "boolean":
if notNull {
return "bool"
}
return "sql.NullBool"

case "date", "datetime", "timestamp":
if notNull {
return "time.Time"
}
return "sql.NullTime"

case "any":
return "interface{}"
Expand All @@ -27,7 +51,14 @@ func sqliteType(r *compiler.Result, col *compiler.Column, settings config.Combin

switch {

case strings.HasPrefix(dt, "varchar"):
case strings.HasPrefix(dt, "character"),
strings.HasPrefix(dt, "varchar"),
strings.HasPrefix(dt, "varyingcharacter"),
strings.HasPrefix(dt, "nchar"),
strings.HasPrefix(dt, "nativecharacter"),
strings.HasPrefix(dt, "nvarchar"),
dt == "text",
dt == "clob":
if notNull {
return "string"
}
Expand Down
4 changes: 2 additions & 2 deletions internal/endtoend/testdata/select_star/sqlite/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.