add binary data type in mapping

This commit is contained in:
ZhengYang 2014-08-19 18:04:22 +08:00
parent 9e2699dbd6
commit e42dc06fd8
1 changed files with 9 additions and 0 deletions

View File

@ -70,6 +70,8 @@ var typeMapping = map[string]string{
"float": "float32", // float & decimal "float": "float32", // float & decimal
"double": "float64", "double": "float64",
"decimal": "float64", "decimal": "float64",
"binary": "string", // binary
"varbinary": "string",
} }
// Table represent a table in a database // Table represent a table in a database
@ -407,6 +409,9 @@ func getColumns(db *sql.DB, table *Table, blackList map[string]bool) {
if isSQLDecimal(dataType) { if isSQLDecimal(dataType) {
tag.Digits, tag.Decimals = extractDecimal(columnType) tag.Digits, tag.Decimals = extractDecimal(columnType)
} }
if isSQLBinaryType(dataType) {
tag.Size = extractColSize(columnType)
}
} }
} }
col.Tag = tag col.Tag = tag
@ -648,6 +653,10 @@ func isSQLDecimal(t string) bool {
return t == "decimal" return t == "decimal"
} }
func isSQLBinaryType(t string) bool {
return t == "binary" || t == "varbinary"
}
// extractColSize extracts field size: e.g. varchar(255) => 255 // extractColSize extracts field size: e.g. varchar(255) => 255
func extractColSize(colType string) string { func extractColSize(colType string) string {
regex := regexp.MustCompile(`^[a-z]+\(([0-9]+)\)$`) regex := regexp.MustCompile(`^[a-z]+\(([0-9]+)\)$`)