Skip to content

Commit 2b5b7e0

Browse files
authored
fix(codegen/golang): Use int8 for MySQL TINYINT (#3298)
1 parent 03fcf3f commit 2b5b7e0

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

internal/codegen/golang/mysql_type.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,22 @@ func mysqlType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.C
3131
} else {
3232
if notNull {
3333
if unsigned {
34-
return "uint32"
34+
return "uint8"
3535
}
36-
return "int32"
36+
return "int8"
3737
}
38-
return "sql.NullInt32"
38+
// The database/sql package does not have a sql.NullInt8 type, so we
39+
// use the smallest type they have which is NullInt16
40+
return "sql.NullInt16"
3941
}
4042

41-
case "smallint", "year":
43+
case "year":
44+
if notNull {
45+
return "int16"
46+
}
47+
return "sql.NullInt16"
48+
49+
case "smallint":
4250
if notNull {
4351
if unsigned {
4452
return "uint16"

internal/endtoend/testdata/datatype/mysql/go/models.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/json/mysql/go/copyfrom.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/vet_explain/mysql/db/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/vet_explain/mysql/db/query.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)