Skip to content

Commit

Permalink
Add support for mysql tiny ints. Closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelnutt2 committed Jun 8, 2016
1 parent 577e442 commit 1a2c8be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Currently only a small portion of mariadb datatypes are supported.

Were applicable sql.Null versions are also supported

- tinyint
- int
- bigint
- decimal
Expand Down
5 changes: 5 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ func stringifyFirstChar(str string) string {
// mysqlTypeToGoType makes mysql to go
func mysqlTypeToGoType(mysqlType string, nullable bool) string {
switch mysqlType {
case "tinyint":
if nullable {
return "sql.NullInt64"
}
return "int"
case "int":
if nullable {
return "sql.NullInt64"
Expand Down
20 changes: 12 additions & 8 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,22 @@ func TestMysqlIntGenerate(t *testing.T) {
`package test
type testStruct struct {
BigIntColumn int64
IntColumn int
NullBigIntColumn sql.NullInt64
NullIntColumn sql.NullInt64
BigIntColumn int64
IntColumn int
NullBigIntColumn sql.NullInt64
NullIntColumn sql.NullInt64
NullTinyIntColumn sql.NullInt64
TinyIntColumn int
}
`

columnMap := map[string]map[string]string{
"intColumn": {"nullable": "NO", "value": "int"},
"nullIntColumn": {"nullable": "YES", "value": "int"},
"bigIntColumn": {"nullable": "NO", "value": "bigint"},
"nullBigIntColumn": {"nullable": "YES", "value": "bigint"},
"intColumn": {"nullable": "NO", "value": "int"},
"nullIntColumn": {"nullable": "YES", "value": "int"},
"tinyIntColumn": {"nullable": "NO", "value": "tinyint"},
"nullTinyIntColumn": {"nullable": "YES", "value": "tinyint"},
"bigIntColumn": {"nullable": "NO", "value": "bigint"},
"nullBigIntColumn": {"nullable": "YES", "value": "bigint"},
}
bytes, err := Generate(columnMap, "testStruct", "test", false, false)

Expand Down

0 comments on commit 1a2c8be

Please sign in to comment.