-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
namer.go
59 lines (45 loc) · 1.56 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package oracle
import (
"strings"
"gorm.io/gorm/schema"
)
type Namer struct {
NamingStrategy schema.Namer
CaseSensitive bool // whether naming is case-sensitive
}
// Deprecated: As of v1.5.0, use the Namer.ConvertNameToFormat instead.
//
//goland:noinspection GoUnusedExportedFunction
func ConvertNameToFormat(x string) string {
return (Namer{}).ConvertNameToFormat(x)
}
func (n Namer) ConvertNameToFormat(x string) string {
if n.CaseSensitive {
return x
}
return strings.ToUpper(x)
}
func (n Namer) TableName(table string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.TableName(table))
}
func (n Namer) ColumnName(table, column string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.ColumnName(table, column))
}
func (n Namer) JoinTableName(table string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.JoinTableName(table))
}
func (n Namer) RelationshipFKName(relationship schema.Relationship) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.RelationshipFKName(relationship))
}
func (n Namer) CheckerName(table, column string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.CheckerName(table, column))
}
func (n Namer) IndexName(table, column string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.IndexName(table, column))
}
func (n Namer) SchemaName(table string) string {
return n.ConvertNameToFormat(n.NamingStrategy.SchemaName(table))
}
func (n Namer) UniqueName(table, column string) string {
return n.ConvertNameToFormat(n.NamingStrategy.UniqueName(table, column))
}