-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
namer.go
70 lines (57 loc) · 2.19 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
60
61
62
63
64
65
66
67
68
69
70
package oracle
import (
"strings"
"gorm.io/gorm/schema"
)
// Namer implement gorm schema namer interface
type Namer struct {
// NamingStrategy use custom naming strategy in gorm.Config on initialize
NamingStrategy schema.Namer
// CaseSensitive determines whether naming is case-sensitive
CaseSensitive bool
}
// Deprecated: As of v1.5.0, use the Namer.ConvertNameToFormat instead.
//
//goland:noinspection GoUnusedExportedFunction
func ConvertNameToFormat(x string) string {
return (Namer{}).ConvertNameToFormat(x)
}
// ConvertNameToFormat return appropriate capitalization name based on CaseSensitive
func (n Namer) ConvertNameToFormat(x string) string {
if n.CaseSensitive {
return x
}
return strings.ToUpper(x)
}
// TableName convert string to table name
func (n Namer) TableName(table string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.TableName(table))
}
// SchemaName generate schema name from table name, don't guarantee it is the reverse value of TableName
func (n Namer) SchemaName(table string) string {
return n.ConvertNameToFormat(n.NamingStrategy.SchemaName(table))
}
// ColumnName convert string to column name
func (n Namer) ColumnName(table, column string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.ColumnName(table, column))
}
// JoinTableName convert string to join table name
func (n Namer) JoinTableName(table string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.JoinTableName(table))
}
// RelationshipFKName generate fk name for relation
func (n Namer) RelationshipFKName(relationship schema.Relationship) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.RelationshipFKName(relationship))
}
// CheckerName generate checker name
func (n Namer) CheckerName(table, column string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.CheckerName(table, column))
}
// IndexName generate index name
func (n Namer) IndexName(table, column string) (name string) {
return n.ConvertNameToFormat(n.NamingStrategy.IndexName(table, column))
}
// UniqueName generate unique constraint name
func (n Namer) UniqueName(table, column string) string {
return n.ConvertNameToFormat(n.NamingStrategy.UniqueName(table, column))
}