gorm/utils.go

47 lines
828 B
Go
Raw Normal View History

2013-10-25 14:04:48 +04:00
package gorm
2013-10-26 05:49:40 +04:00
import (
"bytes"
2013-10-26 05:49:40 +04:00
"fmt"
2013-10-26 05:49:40 +04:00
"strings"
)
2013-10-26 17:37:42 +04:00
func (s *Orm) quote(value string) string {
return "\"" + value + "\""
}
func (s *Orm) quoteMap(values []string) (results []string) {
2013-10-26 06:06:57 +04:00
for _, value := range values {
2013-10-26 17:37:42 +04:00
results = append(results, s.quote(value))
2013-10-26 06:06:57 +04:00
}
return
}
func toSnake(s string) string {
buf := bytes.NewBufferString("")
for i, v := range s {
if i > 0 && v >= 'A' && v <= 'Z' {
buf.WriteRune('_')
}
buf.WriteRune(v)
}
return strings.ToLower(buf.String())
}
func snakeToUpperCamel(s string) string {
buf := bytes.NewBufferString("")
for _, v := range strings.Split(s, "_") {
if len(v) > 0 {
buf.WriteString(strings.ToUpper(v[:1]))
buf.WriteString(v[1:])
}
}
return buf.String()
}
2013-10-26 10:10:47 +04:00
func debug(value interface{}) {
fmt.Printf("***************\n")
fmt.Printf("%+v\n\n", value)
}