From 52ce5351844596a629562b0eddac13843a98e10f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 28 Jul 2021 23:39:34 +0800 Subject: [PATCH] Fix test --- dialects/mysql.go | 14 +++++++++++++- dialects/sqlite3.go | 5 +++-- tags/parser.go | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dialects/mysql.go b/dialects/mysql.go index 0ad68833..21128527 100644 --- a/dialects/mysql.go +++ b/dialects/mysql.go @@ -263,6 +263,7 @@ func (db *mysql) SetParams(params map[string]string) { func (db *mysql) SQLType(c *schemas.Column) string { var res string + var isUnsigned bool switch t := c.SQLType.Name; t { case schemas.Bool: res = schemas.TinyInt @@ -309,8 +310,19 @@ func (db *mysql) SQLType(c *schemas.Column) string { res = schemas.Text case schemas.UnsignedInt: res = schemas.Int + isUnsigned = true case schemas.UnsignedBigInt: 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: res = t } @@ -329,7 +341,7 @@ func (db *mysql) SQLType(c *schemas.Column) string { res += "(" + strconv.Itoa(c.Length) + ")" } - if c.SQLType.Name == schemas.UnsignedBigInt || c.SQLType.Name == schemas.UnsignedInt { + if isUnsigned { res += " UNSIGNED" } diff --git a/dialects/sqlite3.go b/dialects/sqlite3.go index dae6bf93..ac17fd92 100644 --- a/dialects/sqlite3.go +++ b/dialects/sqlite3.go @@ -217,8 +217,9 @@ func (db *sqlite3) SQLType(c *schemas.Column) string { case schemas.Char, schemas.Varchar, schemas.NVarchar, schemas.TinyText, schemas.Text, schemas.MediumText, schemas.LongText, schemas.Json: return schemas.Text - case schemas.Bit, schemas.TinyInt, schemas.SmallInt, schemas.MediumInt, schemas.Int, schemas.Integer, schemas.BigInt, - schemas.UnsignedBigInt, schemas.UnsignedInt: + case schemas.Bit, schemas.TinyInt, schemas.UnsignedTinyInt, schemas.SmallInt, + schemas.UnsignedSmallInt, schemas.MediumInt, schemas.Int, schemas.UnsignedInt, + schemas.BigInt, schemas.UnsignedBigInt, schemas.Integer: return schemas.Integer case schemas.Float, schemas.Double, schemas.Real: return schemas.Real diff --git a/tags/parser.go b/tags/parser.go index cf89211b..e6245a68 100644 --- a/tags/parser.go +++ b/tags/parser.go @@ -218,7 +218,7 @@ func (parser *Parser) parseFieldWithTags(table *schemas.Table, fieldIndex int, f col.SQLType = schemas.Type2SQLType(field.Type) } 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)