Use fluent Set method for Cols initialization

This commit is contained in:
2026-03-29 18:22:00 +02:00
parent d9b5844afb
commit b229e039a3
5 changed files with 29 additions and 11 deletions

View File

@@ -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,
}
}