feat: 新增对mysql unsigned的整型字段的支持,并将created,created_at,updated,updated_at,deleted,deleted_at默认为新增,更新,删除的时间字段标识。
This commit is contained in:
parent
3472d80a6d
commit
f10e21cb15
|
@ -389,9 +389,12 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
||||||
}
|
}
|
||||||
if colType == "FLOAT UNSIGNED" {
|
if colType == "FLOAT UNSIGNED" {
|
||||||
colType = "FLOAT"
|
colType = "FLOAT"
|
||||||
}
|
} else if colType == "DOUBLE UNSIGNED" {
|
||||||
if colType == "DOUBLE UNSIGNED" {
|
|
||||||
colType = "DOUBLE"
|
colType = "DOUBLE"
|
||||||
|
} else {
|
||||||
|
if strings.Index(colType, "UNSIGNED") > 0 {
|
||||||
|
colType = strings.Replace(colType, " UNSIGNED", "_UNSIGNED", -1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
col.Length = len1
|
col.Length = len1
|
||||||
col.Length2 = len2
|
col.Length2 = len2
|
||||||
|
@ -419,6 +422,14 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
|
||||||
col.Default = "'" + col.Default + "'"
|
col.Default = "'" + col.Default + "'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch strings.ToLower(col.Name) {
|
||||||
|
case "created_at", "created":
|
||||||
|
col.IsCreated = true
|
||||||
|
case "updated_at", "updated":
|
||||||
|
col.IsUpdated = true
|
||||||
|
case "deleted_at", "deleted":
|
||||||
|
col.IsDeleted = true
|
||||||
|
}
|
||||||
cols[col.Name] = col
|
cols[col.Name] = col
|
||||||
colSeq = append(colSeq, col.Name)
|
colSeq = append(colSeq, col.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,13 @@ var (
|
||||||
Int = "INT"
|
Int = "INT"
|
||||||
Integer = "INTEGER"
|
Integer = "INTEGER"
|
||||||
BigInt = "BIGINT"
|
BigInt = "BIGINT"
|
||||||
|
// 新增对mysql unsigned 的支撑
|
||||||
|
UTinyInt = "TINYINT_UNSIGNED"
|
||||||
|
USmallInt = "SMALLINT_UNSIGNED"
|
||||||
|
UMediumInt = "MEDIUMINT_UNSIGNED"
|
||||||
|
UInt = "INT_UNSIGNED"
|
||||||
|
UBigInt = "BIGINT_UNSIGNED"
|
||||||
|
// -- end
|
||||||
|
|
||||||
Enum = "ENUM"
|
Enum = "ENUM"
|
||||||
Set = "SET"
|
Set = "SET"
|
||||||
|
@ -139,6 +146,12 @@ var (
|
||||||
Integer: NUMERIC_TYPE,
|
Integer: NUMERIC_TYPE,
|
||||||
BigInt: NUMERIC_TYPE,
|
BigInt: NUMERIC_TYPE,
|
||||||
|
|
||||||
|
UTinyInt: NUMERIC_TYPE,
|
||||||
|
USmallInt: NUMERIC_TYPE,
|
||||||
|
UMediumInt: NUMERIC_TYPE,
|
||||||
|
UInt: NUMERIC_TYPE,
|
||||||
|
UBigInt: NUMERIC_TYPE,
|
||||||
|
|
||||||
Enum: TEXT_TYPE,
|
Enum: TEXT_TYPE,
|
||||||
Set: TEXT_TYPE,
|
Set: TEXT_TYPE,
|
||||||
Json: TEXT_TYPE,
|
Json: TEXT_TYPE,
|
||||||
|
@ -273,10 +286,22 @@ var (
|
||||||
// Type2SQLType generate SQLType acorrding Go's type
|
// Type2SQLType generate SQLType acorrding Go's type
|
||||||
func Type2SQLType(t reflect.Type) (st SQLType) {
|
func Type2SQLType(t reflect.Type) (st SQLType) {
|
||||||
switch k := t.Kind(); k {
|
switch k := t.Kind(); k {
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32:
|
case reflect.Int, reflect.Int32:
|
||||||
st = SQLType{Int, 0, 0}
|
st = SQLType{Int, 0, 0}
|
||||||
case reflect.Int64, reflect.Uint64:
|
case reflect.Int16:
|
||||||
|
st = SQLType{SmallInt, 0, 0}
|
||||||
|
case reflect.Uint16:
|
||||||
|
st = SQLType{USmallInt, 0, 0}
|
||||||
|
case reflect.Uint:
|
||||||
|
st = SQLType{UInt, 0, 0}
|
||||||
|
case reflect.Int8:
|
||||||
|
st = SQLType{TinyInt, 0, 0}
|
||||||
|
case reflect.Uint8:
|
||||||
|
st = SQLType{UTinyInt, 0, 0}
|
||||||
|
case reflect.Int64:
|
||||||
st = SQLType{BigInt, 0, 0}
|
st = SQLType{BigInt, 0, 0}
|
||||||
|
case reflect.Uint64:
|
||||||
|
st = SQLType{UBigInt, 0, 0}
|
||||||
case reflect.Float32:
|
case reflect.Float32:
|
||||||
st = SQLType{Float, 0, 0}
|
st = SQLType{Float, 0, 0}
|
||||||
case reflect.Float64:
|
case reflect.Float64:
|
||||||
|
@ -312,8 +337,18 @@ func Type2SQLType(t reflect.Type) (st SQLType) {
|
||||||
func SQLType2Type(st SQLType) reflect.Type {
|
func SQLType2Type(st SQLType) reflect.Type {
|
||||||
name := strings.ToUpper(st.Name)
|
name := strings.ToUpper(st.Name)
|
||||||
switch name {
|
switch name {
|
||||||
case Bit, TinyInt, SmallInt, MediumInt, Int, Integer, Serial:
|
case SmallInt:
|
||||||
return reflect.TypeOf(1)
|
return reflect.TypeOf(int16(1))
|
||||||
|
case USmallInt:
|
||||||
|
return reflect.TypeOf(uint16(1))
|
||||||
|
case MediumInt, Int, Integer, Serial:
|
||||||
|
return reflect.TypeOf(int32(1))
|
||||||
|
case Bit, TinyInt:
|
||||||
|
return reflect.TypeOf(int8(1))
|
||||||
|
case UTinyInt:
|
||||||
|
return reflect.TypeOf(uint8(1))
|
||||||
|
case UBigInt:
|
||||||
|
return reflect.TypeOf(uint64(1))
|
||||||
case BigInt, BigSerial:
|
case BigInt, BigSerial:
|
||||||
return reflect.TypeOf(int64(1))
|
return reflect.TypeOf(int64(1))
|
||||||
case Float, Real:
|
case Float, Real:
|
||||||
|
|
Loading…
Reference in New Issue