oracle/namer.go

55 lines
1.4 KiB
Go
Raw Normal View History

2024-05-09 16:59:25 +08:00
package oracle
import (
2024-05-10 11:28:44 +08:00
"fmt"
2024-05-10 10:27:21 +08:00
"strings"
2024-05-10 11:28:44 +08:00
"gorm.io/gorm/schema"
2024-05-09 16:59:25 +08:00
)
type Namer struct {
2024-05-10 11:28:44 +08:00
NamingStrategy schema.Namer
DBName string
2024-05-09 16:59:25 +08:00
}
2024-05-10 10:27:21 +08:00
func ConvertNameToFormat(x string) string {
2024-05-09 16:59:25 +08:00
return strings.ToUpper(x)
}
func (n Namer) TableName(table string) (name string) {
2024-05-10 11:28:44 +08:00
tableName := ConvertNameToFormat(n.NamingStrategy.TableName(table))
if len(n.DBName) > 0 {
return fmt.Sprintf("%s.%s", n.DBName, tableName)
}
return tableName
2024-05-09 16:59:25 +08:00
}
func (n Namer) ColumnName(table, column string) (name string) {
2024-05-10 10:27:21 +08:00
return ConvertNameToFormat(n.NamingStrategy.ColumnName(table, column))
2024-05-09 16:59:25 +08:00
}
func (n Namer) JoinTableName(table string) (name string) {
2024-05-10 10:27:21 +08:00
return ConvertNameToFormat(n.NamingStrategy.JoinTableName(table))
2024-05-09 16:59:25 +08:00
}
func (n Namer) RelationshipFKName(relationship schema.Relationship) (name string) {
2024-05-10 10:27:21 +08:00
return ConvertNameToFormat(n.NamingStrategy.RelationshipFKName(relationship))
2024-05-09 16:59:25 +08:00
}
func (n Namer) CheckerName(table, column string) (name string) {
2024-05-10 10:27:21 +08:00
return ConvertNameToFormat(n.NamingStrategy.CheckerName(table, column))
2024-05-09 16:59:25 +08:00
}
func (n Namer) IndexName(table, column string) (name string) {
2024-05-10 10:27:21 +08:00
return ConvertNameToFormat(n.NamingStrategy.IndexName(table, column))
2024-05-09 16:59:25 +08:00
}
2024-05-10 11:28:44 +08:00
func (n Namer) SchemaName(table string) string {
return ConvertNameToFormat(n.NamingStrategy.SchemaName(table))
}
func (n Namer) UniqueName(table, column string) string {
return ConvertNameToFormat(n.NamingStrategy.UniqueName(table, column))
}