2013-10-25 14:04:48 +04:00
|
|
|
package gorm
|
2013-10-26 05:49:40 +04:00
|
|
|
|
|
|
|
import (
|
2013-10-26 10:23:02 +04:00
|
|
|
"bytes"
|
2013-10-26 05:49:40 +04:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-02-18 04:26:35 +03:00
|
|
|
var smap = map[string]string{}
|
2013-12-15 06:09:19 +04:00
|
|
|
|
2015-02-18 04:26:35 +03:00
|
|
|
func ToDBColumnName(u string) string {
|
|
|
|
if v, ok := smap[u]; ok {
|
2013-11-17 04:28:30 +04:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2013-10-26 10:23:02 +04:00
|
|
|
buf := bytes.NewBufferString("")
|
2013-11-17 04:28:30 +04:00
|
|
|
for i, v := range u {
|
2013-10-26 10:23:02 +04:00
|
|
|
if i > 0 && v >= 'A' && v <= 'Z' {
|
|
|
|
buf.WriteRune('_')
|
|
|
|
}
|
|
|
|
buf.WriteRune(v)
|
|
|
|
}
|
2013-11-17 04:28:30 +04:00
|
|
|
|
|
|
|
s := strings.ToLower(buf.String())
|
2015-02-18 04:26:35 +03:00
|
|
|
smap[u] = s
|
2013-11-17 04:28:30 +04:00
|
|
|
return s
|
2013-10-26 10:23:02 +04:00
|
|
|
}
|
|
|
|
|
2014-07-29 13:52:23 +04:00
|
|
|
func parseTagSetting(str string) map[string]string {
|
|
|
|
tags := strings.Split(str, ";")
|
|
|
|
setting := map[string]string{}
|
|
|
|
for _, value := range tags {
|
|
|
|
v := strings.Split(value, ":")
|
|
|
|
k := strings.TrimSpace(strings.ToUpper(v[0]))
|
|
|
|
if len(v) == 2 {
|
|
|
|
setting[k] = v[1]
|
|
|
|
} else {
|
|
|
|
setting[k] = k
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return setting
|
|
|
|
}
|