This commit is contained in:
Lunny Xiao 2021-07-28 23:39:34 +08:00
parent c88bb03dd8
commit 52ce535184
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 17 additions and 4 deletions

View File

@ -263,6 +263,7 @@ func (db *mysql) SetParams(params map[string]string) {
func (db *mysql) SQLType(c *schemas.Column) string { func (db *mysql) SQLType(c *schemas.Column) string {
var res string var res string
var isUnsigned bool
switch t := c.SQLType.Name; t { switch t := c.SQLType.Name; t {
case schemas.Bool: case schemas.Bool:
res = schemas.TinyInt res = schemas.TinyInt
@ -309,8 +310,19 @@ func (db *mysql) SQLType(c *schemas.Column) string {
res = schemas.Text res = schemas.Text
case schemas.UnsignedInt: case schemas.UnsignedInt:
res = schemas.Int res = schemas.Int
isUnsigned = true
case schemas.UnsignedBigInt: case schemas.UnsignedBigInt:
res = schemas.BigInt res = schemas.BigInt
isUnsigned = true
case schemas.UnsignedMediumInt:
res = schemas.MediumInt
isUnsigned = true
case schemas.UnsignedSmallInt:
res = schemas.SmallInt
isUnsigned = true
case schemas.UnsignedTinyInt:
res = schemas.TinyInt
isUnsigned = true
default: default:
res = t res = t
} }
@ -329,7 +341,7 @@ func (db *mysql) SQLType(c *schemas.Column) string {
res += "(" + strconv.Itoa(c.Length) + ")" res += "(" + strconv.Itoa(c.Length) + ")"
} }
if c.SQLType.Name == schemas.UnsignedBigInt || c.SQLType.Name == schemas.UnsignedInt { if isUnsigned {
res += " UNSIGNED" res += " UNSIGNED"
} }

View File

@ -217,8 +217,9 @@ func (db *sqlite3) SQLType(c *schemas.Column) string {
case schemas.Char, schemas.Varchar, schemas.NVarchar, schemas.TinyText, case schemas.Char, schemas.Varchar, schemas.NVarchar, schemas.TinyText,
schemas.Text, schemas.MediumText, schemas.LongText, schemas.Json: schemas.Text, schemas.MediumText, schemas.LongText, schemas.Json:
return schemas.Text return schemas.Text
case schemas.Bit, schemas.TinyInt, schemas.SmallInt, schemas.MediumInt, schemas.Int, schemas.Integer, schemas.BigInt, case schemas.Bit, schemas.TinyInt, schemas.UnsignedTinyInt, schemas.SmallInt,
schemas.UnsignedBigInt, schemas.UnsignedInt: schemas.UnsignedSmallInt, schemas.MediumInt, schemas.Int, schemas.UnsignedInt,
schemas.BigInt, schemas.UnsignedBigInt, schemas.Integer:
return schemas.Integer return schemas.Integer
case schemas.Float, schemas.Double, schemas.Real: case schemas.Float, schemas.Double, schemas.Real:
return schemas.Real return schemas.Real

View File

@ -218,7 +218,7 @@ func (parser *Parser) parseFieldWithTags(table *schemas.Table, fieldIndex int, f
col.SQLType = schemas.Type2SQLType(field.Type) col.SQLType = schemas.Type2SQLType(field.Type)
} }
if ctx.isUnsigned && col.SQLType.IsNumeric() && !strings.HasPrefix(col.SQLType.Name, "UNSIGNED") { if ctx.isUnsigned && col.SQLType.IsNumeric() && !strings.HasPrefix(col.SQLType.Name, "UNSIGNED") {
col.SQLType.Name = col.SQLType.Name + " UNSIGNED" col.SQLType.Name = "UNSIGNED " + col.SQLType.Name
} }
parser.dialect.SQLType(col) parser.dialect.SQLType(col)