initial
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user