1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 23:50:54 +00:00

Merge pull request #54 from ZhengYang/master

add binary data type in mapping
This commit is contained in:
astaxie 2014-08-19 18:06:32 +08:00
commit f4e53e84ec

View File

@ -70,6 +70,8 @@ var typeMapping = map[string]string{
"float": "float32", // float & decimal
"double": "float64",
"decimal": "float64",
"binary": "string", // binary
"varbinary": "string",
}
// 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) {
tag.Digits, tag.Decimals = extractDecimal(columnType)
}
if isSQLBinaryType(dataType) {
tag.Size = extractColSize(columnType)
}
}
}
col.Tag = tag
@ -648,6 +653,10 @@ func isSQLDecimal(t string) bool {
return t == "decimal"
}
func isSQLBinaryType(t string) bool {
return t == "binary" || t == "varbinary"
}
// extractColSize extracts field size: e.g. varchar(255) => 255
func extractColSize(colType string) string {
regex := regexp.MustCompile(`^[a-z]+\(([0-9]+)\)$`)