Use fluent Set method for Cols initialization
This commit is contained in:
28
gormcol.go
28
gormcol.go
@@ -9,19 +9,33 @@
|
||||
// IDProfile gormcol.Field
|
||||
// IDAuthorizationRole gormcol.Field
|
||||
// }{
|
||||
// IDProfile: gormcol.Field{Table: (PsAccess{}).TableName(), Column: "id_profile"},
|
||||
// IDAuthorizationRole: gormcol.Field{Table: (PsAccess{}).TableName(), Column: "id_authorization_role"},
|
||||
// IDProfile: gormcol.Field{}.Set((&PsAccess{}).TableName(), "id_profile"),
|
||||
// IDAuthorizationRole: gormcol.Field{}.Set((&PsAccess{}).TableName(), "id_authorization_role"),
|
||||
// }
|
||||
package gormcol
|
||||
|
||||
// Field represents a GORM column descriptor.
|
||||
// Table should be set using the model's TableName() function for type safety.
|
||||
type Field struct {
|
||||
Table string // Database table name (use model's TableName())
|
||||
Column string // Database column name
|
||||
table string // Database table name (use model's TableName())
|
||||
column string // Database column name
|
||||
}
|
||||
|
||||
// Column returns the column name from a Field descriptor.
|
||||
func Column(f Field) string {
|
||||
return f.Column
|
||||
func (f Field) TabCol() string {
|
||||
return f.table + "." + f.column
|
||||
}
|
||||
|
||||
func (f Field) Col() string {
|
||||
return f.column
|
||||
}
|
||||
|
||||
func (f Field) Tab() string {
|
||||
return f.table
|
||||
}
|
||||
|
||||
func (f Field) Set(tab, field string) Field {
|
||||
return Field{
|
||||
table: tab,
|
||||
column: field,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user