forked from nfjBill/gorm-driver-dm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamer.go
45 lines (34 loc) · 1.15 KB
/
namer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package dm
import (
"gorm.io/gorm/schema"
"strings"
)
type Namer struct {
schema.NamingStrategy
}
func ConvertNameToFormat(x string) string {
return strings.ToUpper(x)
}
func (n Namer) TableName(table string) (name string) {
return ConvertNameToFormat(n.NamingStrategy.TableName(table))
}
func (n Namer) ColumnName(table, column string) (name string) {
return ConvertNameToFormat(n.NamingStrategy.ColumnName(table, column))
}
func (n Namer) JoinTableName(table string) (name string) {
return ConvertNameToFormat(n.NamingStrategy.JoinTableName(table))
}
func (n Namer) RelationshipFKName(relationship schema.Relationship) (name string) {
return ConvertNameToFormat(n.NamingStrategy.RelationshipFKName(relationship))
}
func (n Namer) CheckerName(table, column string) (name string) {
return ConvertNameToFormat(n.NamingStrategy.CheckerName(table, column))
}
func (n Namer) IndexName(table, column string) (name string) {
tlc := strings.ToLower(column)
cl := n.NamingStrategy.IndexName(table, column)
if strings.Contains(tlc, "idx_"+strings.ToLower(table)) && strings.Contains(tlc, strings.ToLower(column)) {
cl = column
}
return ConvertNameToFormat(cl)
}