35 lines
874 B
Go
35 lines
874 B
Go
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
|
|
}
|
|
|
|
// TabCol returns the fully qualified "table.column" reference.
|
|
func (f Field) TabCol() string {
|
|
return f.table + "." + f.column
|
|
}
|
|
|
|
// Col returns the column name without table qualification.
|
|
func (f Field) Col() string {
|
|
return f.column
|
|
}
|
|
|
|
// Tab returns the table name.
|
|
func (f Field) Tab() string {
|
|
return f.table
|
|
}
|
|
|
|
// Set initializes a Field with the given table and column names.
|
|
// Use with TableName() for type-safe initialization, e.g.:
|
|
//
|
|
// Field{}.Set((&MyModel{}).TableName(), "column_name")
|
|
func (f Field) Set(tab, field string) Field {
|
|
return Field{
|
|
table: tab,
|
|
column: field,
|
|
}
|
|
}
|