commit
8e8100f5f0
1 changed files with 45 additions and 8 deletions
|
@ -272,23 +272,42 @@ func (m *MySQLDriver) ForeignKeyInfo(schema, tableName string) ([]bdb.ForeignKey
|
||||||
// "varchar" to "string" and "bigint" to "int64". It returns this parsed data
|
// "varchar" to "string" and "bigint" to "int64". It returns this parsed data
|
||||||
// as a Column object.
|
// as a Column object.
|
||||||
func (m *MySQLDriver) TranslateColumnType(c bdb.Column) bdb.Column {
|
func (m *MySQLDriver) TranslateColumnType(c bdb.Column) bdb.Column {
|
||||||
|
unsigned := strings.Contains(c.FullDBType, "unsigned")
|
||||||
if c.Nullable {
|
if c.Nullable {
|
||||||
switch c.DBType {
|
switch c.DBType {
|
||||||
case "tinyint":
|
case "tinyint":
|
||||||
// map tinyint(1) to bool if TinyintAsBool is true
|
// map tinyint(1) to bool if TinyintAsBool is true
|
||||||
if TinyintAsBool && c.FullDBType == "tinyint(1)" {
|
if TinyintAsBool && c.FullDBType == "tinyint(1)" {
|
||||||
c.Type = "null.Bool"
|
c.Type = "null.Bool"
|
||||||
|
} else if unsigned {
|
||||||
|
c.Type = "null.Uint8"
|
||||||
} else {
|
} else {
|
||||||
c.Type = "null.Int8"
|
c.Type = "null.Int8"
|
||||||
}
|
}
|
||||||
case "smallint":
|
case "smallint":
|
||||||
|
if unsigned {
|
||||||
|
c.Type = "null.Uint16"
|
||||||
|
} else {
|
||||||
c.Type = "null.Int16"
|
c.Type = "null.Int16"
|
||||||
|
}
|
||||||
case "mediumint":
|
case "mediumint":
|
||||||
|
if unsigned {
|
||||||
|
c.Type = "null.Uint32"
|
||||||
|
} else {
|
||||||
c.Type = "null.Int32"
|
c.Type = "null.Int32"
|
||||||
|
}
|
||||||
case "int", "integer":
|
case "int", "integer":
|
||||||
|
if unsigned {
|
||||||
|
c.Type = "null.Uint"
|
||||||
|
} else {
|
||||||
c.Type = "null.Int"
|
c.Type = "null.Int"
|
||||||
|
}
|
||||||
case "bigint":
|
case "bigint":
|
||||||
c.Type = "null.Int64"
|
if unsigned {
|
||||||
|
c.Type = "null.Uint64"
|
||||||
|
} else {
|
||||||
|
c.Type = "null.Uint64"
|
||||||
|
}
|
||||||
case "float":
|
case "float":
|
||||||
c.Type = "null.Float32"
|
c.Type = "null.Float32"
|
||||||
case "double", "double precision", "real":
|
case "double", "double precision", "real":
|
||||||
|
@ -310,17 +329,35 @@ func (m *MySQLDriver) TranslateColumnType(c bdb.Column) bdb.Column {
|
||||||
// map tinyint(1) to bool if TinyintAsBool is true
|
// map tinyint(1) to bool if TinyintAsBool is true
|
||||||
if TinyintAsBool && c.FullDBType == "tinyint(1)" {
|
if TinyintAsBool && c.FullDBType == "tinyint(1)" {
|
||||||
c.Type = "bool"
|
c.Type = "bool"
|
||||||
|
} else if unsigned {
|
||||||
|
c.Type = "uint8"
|
||||||
} else {
|
} else {
|
||||||
c.Type = "int8"
|
c.Type = "int8"
|
||||||
}
|
}
|
||||||
case "smallint":
|
case "smallint":
|
||||||
|
if unsigned {
|
||||||
|
c.Type = "uint16"
|
||||||
|
} else {
|
||||||
c.Type = "int16"
|
c.Type = "int16"
|
||||||
|
}
|
||||||
case "mediumint":
|
case "mediumint":
|
||||||
|
if unsigned {
|
||||||
|
c.Type = "uint32"
|
||||||
|
} else {
|
||||||
c.Type = "int32"
|
c.Type = "int32"
|
||||||
|
}
|
||||||
case "int", "integer":
|
case "int", "integer":
|
||||||
|
if unsigned {
|
||||||
|
c.Type = "uint"
|
||||||
|
} else {
|
||||||
c.Type = "int"
|
c.Type = "int"
|
||||||
|
}
|
||||||
case "bigint":
|
case "bigint":
|
||||||
|
if unsigned {
|
||||||
|
c.Type = "uint64"
|
||||||
|
} else {
|
||||||
c.Type = "int64"
|
c.Type = "int64"
|
||||||
|
}
|
||||||
case "float":
|
case "float":
|
||||||
c.Type = "float32"
|
c.Type = "float32"
|
||||||
case "double", "double precision", "real":
|
case "double", "double precision", "real":
|
||||||
|
|
Loading…
Reference in a new issue