35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
// Package gormcol provides type-safe GORM column descriptors.
|
|
//
|
|
// This package enables defining struct-like variables that map Go field names
|
|
// to database column names, allowing type-safe queries in GORM.
|
|
//
|
|
// Example usage:
|
|
//
|
|
// var PsAccessCols = struct {
|
|
// IDProfile gormcol.Field
|
|
// IDAuthorizationRole gormcol.Field
|
|
// }{
|
|
// IDProfile: gormcol.Field{Column: "id_profile"},
|
|
// IDAuthorizationRole: gormcol.Field{Column: "id_authorization_role"},
|
|
// }
|
|
//
|
|
// Then in queries, use the model's TableName():
|
|
//
|
|
// PsAccess{}.TableName() + "." + gormcol.Column(PsAccessCols.IDProfile) // "ps_access.id_profile"
|
|
package gormcol
|
|
|
|
// Field represents a GORM column descriptor.
|
|
// It holds only the column name; use the model's TableName() for table qualification.
|
|
type Field struct {
|
|
Column string // Database column name
|
|
}
|
|
|
|
// Column returns the column name from a Field descriptor.
|
|
//
|
|
// Example:
|
|
//
|
|
// gormcol.Column(dbmodel.PsAccessCols.IDAuthorizationRole) // "id_authorization_role"
|
|
func Column(f Field) string {
|
|
return f.Column
|
|
}
|