From 7b90ea8d13bb65b943eff55c82c19846c8a402b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=86=E8=AE=AF=E5=9C=A8=E7=BA=BF?= Date: Wed, 19 Nov 2014 00:42:40 +0800 Subject: [PATCH] Increase TableName method used to obtain the full table name --- mapper.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mapper.go b/mapper.go index 8fc115f1..c00dc395 100644 --- a/mapper.go +++ b/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} }