mirror of
https://github.com/beego/bee.git
synced 2024-11-22 05:00:54 +00:00
Merge pull request #54 from ZhengYang/master
add binary data type in mapping
This commit is contained in:
commit
f4e53e84ec
@ -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]+)\)$`)
|
||||||
|
Loading…
Reference in New Issue
Block a user