36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package gormcol
|
|
|
|
// Field represents a GORM column descriptor with table context.
|
|
// Define package-level variables to get type-safe column references:
|
|
//
|
|
// var PsAccess = struct {
|
|
// IDProfile gormcol.Field
|
|
// IDAuthorizationRole gormcol.Field
|
|
// }{
|
|
// IDProfile: gormcol.Field{Table: "ps_access", Column: "id_profile"},
|
|
// IDAuthorizationRole: gormcol.Field{Table: "ps_access", Column: "id_authorization_role"},
|
|
// }
|
|
type Field struct {
|
|
Table string
|
|
Column string
|
|
}
|
|
|
|
// Column returns the column name from a Field descriptor.
|
|
//
|
|
// gormcol.Column(prestadb.PsAccess.IDAuthorizationRole) // "id_authorization_role"
|
|
func Column(f Field) string {
|
|
return f.Column
|
|
}
|
|
|
|
// ColumnOnTable returns "table.column" from a Field descriptor.
|
|
//
|
|
// gormcol.ColumnOnTable(prestadb.PsAccess.IDAuthorizationRole) // "ps_access.id_authorization_role"
|
|
func ColumnOnTable(f Field) string {
|
|
return f.Table + "." + f.Column
|
|
}
|
|
|
|
// TableField returns the table name from a Field descriptor.
|
|
func TableField(f Field) string {
|
|
return f.Table
|
|
}
|