Increase TableName method used to obtain the full table name
This commit is contained in:
parent
3e0fa232ab
commit
7b90ea8d13
20
mapper.go
20
mapper.go
|
@ -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}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue