1
0
mirror of https://github.com/beego/bee.git synced 2024-12-22 20:20:49 +00:00

add binary data type in mapping

This commit is contained in:
ZhengYang 2014-08-19 18:04:22 +08:00
parent 9e2699dbd6
commit e42dc06fd8

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]+)\)$`)