1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Upgrade xorm to v1.1.0 (#15869)

This commit is contained in:
Lunny Xiao
2021-05-15 03:17:06 +08:00
committed by GitHub
parent e2f39c2b64
commit f6be429781
55 changed files with 1309 additions and 438 deletions

18
vendor/xorm.io/xorm/names/mapper.go generated vendored
View File

@@ -16,6 +16,7 @@ type Mapper interface {
Table2Obj(string) string
}
// CacheMapper represents a cache mapper
type CacheMapper struct {
oriMapper Mapper
obj2tableCache map[string]string
@@ -24,12 +25,14 @@ type CacheMapper struct {
table2objMutex sync.RWMutex
}
// NewCacheMapper creates a cache mapper
func NewCacheMapper(mapper Mapper) *CacheMapper {
return &CacheMapper{oriMapper: mapper, obj2tableCache: make(map[string]string),
table2objCache: make(map[string]string),
}
}
// Obj2Table implements Mapper
func (m *CacheMapper) Obj2Table(o string) string {
m.obj2tableMutex.RLock()
t, ok := m.obj2tableCache[o]
@@ -45,6 +48,7 @@ func (m *CacheMapper) Obj2Table(o string) string {
return t
}
// Table2Obj implements Mapper
func (m *CacheMapper) Table2Obj(t string) string {
m.table2objMutex.RLock()
o, ok := m.table2objCache[t]
@@ -60,15 +64,17 @@ func (m *CacheMapper) Table2Obj(t string) string {
return o
}
// SameMapper implements IMapper and provides same name between struct and
// SameMapper implements Mapper and provides same name between struct and
// database table
type SameMapper struct {
}
// Obj2Table implements Mapper
func (m SameMapper) Obj2Table(o string) string {
return o
}
// Table2Obj implements Mapper
func (m SameMapper) Table2Obj(t string) string {
return t
}
@@ -98,6 +104,7 @@ func snakeCasedName(name string) string {
return b2s(newstr)
}
// Obj2Table implements Mapper
func (mapper SnakeMapper) Obj2Table(name string) string {
return snakeCasedName(name)
}
@@ -127,6 +134,7 @@ func titleCasedName(name string) string {
return b2s(newstr)
}
// Table2Obj implements Mapper
func (mapper SnakeMapper) Table2Obj(name string) string {
return titleCasedName(name)
}
@@ -168,10 +176,12 @@ func gonicCasedName(name string) string {
return strings.ToLower(string(newstr))
}
// Obj2Table implements Mapper
func (mapper GonicMapper) Obj2Table(name string) string {
return gonicCasedName(name)
}
// Table2Obj implements Mapper
func (mapper GonicMapper) Table2Obj(name string) string {
newstr := make([]rune, 0)
@@ -234,14 +244,17 @@ type PrefixMapper struct {
Prefix string
}
// Obj2Table implements Mapper
func (mapper PrefixMapper) Obj2Table(name string) string {
return mapper.Prefix + mapper.Mapper.Obj2Table(name)
}
// Table2Obj implements Mapper
func (mapper PrefixMapper) Table2Obj(name string) string {
return mapper.Mapper.Table2Obj(name[len(mapper.Prefix):])
}
// NewPrefixMapper creates a prefix mapper
func NewPrefixMapper(mapper Mapper, prefix string) PrefixMapper {
return PrefixMapper{mapper, prefix}
}
@@ -252,14 +265,17 @@ type SuffixMapper struct {
Suffix string
}
// Obj2Table implements Mapper
func (mapper SuffixMapper) Obj2Table(name string) string {
return mapper.Mapper.Obj2Table(name) + mapper.Suffix
}
// Table2Obj implements Mapper
func (mapper SuffixMapper) Table2Obj(name string) string {
return mapper.Mapper.Table2Obj(name[:len(name)-len(mapper.Suffix)])
}
// NewSuffixMapper creates a suffix mapper
func NewSuffixMapper(mapper Mapper, suffix string) SuffixMapper {
return SuffixMapper{mapper, suffix}
}