From e42dc06fd8a0db863f9eeb1977dc948aee679ebb Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Tue, 19 Aug 2014 18:04:22 +0800 Subject: [PATCH] add binary data type in mapping --- g_appcode.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/g_appcode.go b/g_appcode.go index cfca8be..6cdf29b 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -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]+)\)$`)