support enum type for mysql

Signed-off-by: 商讯在线 <swhbox@foxmail.com>
This commit is contained in:
商讯在线 2014-05-05 22:33:28 +08:00
parent 724a99021f
commit c42f893230
2 changed files with 24 additions and 3 deletions

View File

@ -31,11 +31,30 @@ type Column struct {
IsVersion bool
fieldPath []string
DefaultIsEmpty bool
EnumOptions map[string]int
}
func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column {
return &Column{name, fieldName, sqlType, len1, len2, nullable, "", make(map[string]bool), false, false,
TWOSIDES, false, false, false, false, nil, false}
return &Column{
Name: name,
FieldName: fieldName,
SQLType: sqlType,
Length: len1,
Length2: len2,
Nullable: nullable,
Default: "",
Indexes: make(map[string]bool),
IsPrimaryKey: false,
IsAutoIncrement: false,
MapType: TWOSIDES,
IsCreated: false,
IsUpdated: false,
IsCascade: false,
IsVersion: false,
fieldPath: nil,
DefaultIsEmpty: false,
EnumOptions: make(map[string]int),
}
}
// generate column description string according dialect

View File

@ -62,6 +62,7 @@ var (
Integer = "INTEGER"
BigInt = "BIGINT"
Enum = "ENUM"
Char = "CHAR"
Varchar = "VARCHAR"
TinyText = "TINYTEXT"
@ -104,6 +105,7 @@ var (
Integer: NUMERIC_TYPE,
BigInt: NUMERIC_TYPE,
Enum: TEXT_TYPE,
Char: TEXT_TYPE,
Varchar: TEXT_TYPE,
TinyText: TEXT_TYPE,
@ -293,7 +295,7 @@ func SQLType2Type(st SQLType) reflect.Type {
return reflect.TypeOf(float32(1))
case Double:
return reflect.TypeOf(float64(1))
case Char, Varchar, TinyText, Text, MediumText, LongText:
case Char, Varchar, TinyText, Text, MediumText, LongText, Enum:
return reflect.TypeOf("")
case TinyBlob, Blob, LongBlob, Bytea, Binary, MediumBlob, VarBinary:
return reflect.TypeOf([]byte{})