Skip to content

Commit

Permalink
fix isNUll and add decimal float double tinyint
Browse files Browse the repository at this point in the history
  • Loading branch information
fifsky committed Mar 19, 2020
1 parent 5af9dd2 commit 1cc4d13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ genstruct -h localhost -u root -p 3306 -P 123456
* `-u` default `root`
* `-p` default `3306`

## online

https://go.fifsky.com/

## gosql

The structure can be applied to a [gosql](https://github.com/ilibs/gosql) package
Expand Down
28 changes: 25 additions & 3 deletions generator/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,41 @@ func GetParams(cmds []string, i int) (string, error) {
return strings.TrimSpace(cmds[i]), nil
}

func typeFormat(t string) string {
if t == "datetime" || t == "date" {
func typeFormat(t string, isNull string) string {
if t == "datetime" || t == "date" || t == "time" {
if isNull == "YES" {
return "sql.NullTime"
}
return "time.Time"
}

if len(t) >= 6 && t[0:6] == "bigint" {
if isNull == "YES" {
return "sql.NullInt64"
}
return "int64"
}

if strings.Index(t, "int") != -1 {
if strings.Index(t, "int") != -1 || strings.Index(t, "tinyint") != -1 {
if isNull == "YES" {
return "sql.NullInt64"
}

return "int"
}

if strings.Index(t, "decimal") != -1 || strings.Index(t, "float") != -1 || strings.Index(t, "double") != -1 {
if isNull == "YES" {
return "sql.NullFloat64"
}

return "float64"
}

if isNull == "YES" {
return "sql.NullString"
}

return "string"
}

Expand Down

0 comments on commit 1cc4d13

Please sign in to comment.