Files
gormcol/gormcol.go

28 lines
941 B
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{Table: (PsAccess{}).TableName(), Column: "id_profile"},
// IDAuthorizationRole: gormcol.Field{Table: (PsAccess{}).TableName(), Column: "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
}
// Column returns the column name from a Field descriptor.
func Column(f Field) string {
return f.Column
}