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

support bit type

This commit is contained in:
astaxie 2014-08-27 11:08:32 +08:00
parent 7ffe1060cc
commit b3674b5b06

View File

@ -76,6 +76,7 @@ var typeMappingMysql = map[string]string{
"smallint unsigned": "uint16",
"mediumint unsigned": "uint32",
"bigint unsigned": "uint64",
"bit": "uint64",
"bool": "bool", // boolean
"enum": "string", // enum
"set": "string", // set
@ -480,6 +481,9 @@ func (mysqlDB *MysqlDB) GetColumns(db *sql.DB, table *Table, blackList map[strin
if isSQLBinaryType(dataType) {
tag.Size = extractColSize(columnType)
}
if isSQLBitType(dataType) {
tag.Size = extractColSize(columnType)
}
}
}
col.Tag = tag
@ -904,6 +908,10 @@ func isSQLBinaryType(t string) bool {
return t == "binary" || t == "varbinary"
}
func isSQLBitType(t string) bool {
return t == "bit"
}
// extractColSize extracts field size: e.g. varchar(255) => 255
func extractColSize(colType string) string {
regex := regexp.MustCompile(`^[a-z]+\(([0-9]+)\)$`)