Merge branch 'master' of github.com:go-xorm/core

This commit is contained in:
Lunny Xiao 2014-11-20 15:08:47 +08:00
commit 8552a6e846
1 changed files with 20 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
type IMapper interface {
Obj2Table(string) string
Table2Obj(string) string
TableName(string) string
}
type CacheMapper struct {
@ -55,6 +56,10 @@ func (m *CacheMapper) Table2Obj(t string) string {
return o
}
func (m *CacheMapper) TableName(t string) string {
return t
}
// SameMapper implements IMapper and provides same name between struct and
// database table
type SameMapper struct {
@ -68,6 +73,10 @@ func (m SameMapper) Table2Obj(t string) string {
return t
}
func (m SameMapper) TableName(t string) string {
return t
}
// SnakeMapper implements IMapper and provides name transaltion between
// struct and database table
type SnakeMapper struct {
@ -139,6 +148,9 @@ func (mapper SnakeMapper) Table2Obj(name string) string {
return titleCasedName(name)
}
func (mapper SnakeMapper) TableName(t string) string {
return t
}
// provide prefix table name support
type PrefixMapper struct {
Mapper IMapper
@ -153,6 +165,10 @@ func (mapper PrefixMapper) Table2Obj(name string) string {
return mapper.Mapper.Table2Obj(name[len(mapper.Prefix):])
}
func (mapper PrefixMapper) TableName(name string) string {
return mapper.Prefix + name
}
func NewPrefixMapper(mapper IMapper, prefix string) PrefixMapper {
return PrefixMapper{mapper, prefix}
}
@ -171,6 +187,10 @@ func (mapper SuffixMapper) Table2Obj(name string) string {
return mapper.Mapper.Table2Obj(name[:len(name)-len(mapper.Suffix)])
}
func (mapper SuffixMapper) TableName(name string) string {
return name + mapper.Suffix
}
func NewSuffixMapper(mapper IMapper, suffix string) SuffixMapper {
return SuffixMapper{mapper, suffix}
}