diff --git a/app/model/dbmodel/ps_access.go b/app/model/dbmodel/ps_access.go deleted file mode 100644 index 2b32410..0000000 --- a/app/model/dbmodel/ps_access.go +++ /dev/null @@ -1,28 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package dbmodel - -import "git.ma-al.com/goc_marek/gormcol" - -const TableNamePsAccess = "ps_access" - -// PsAccess mapped from table -type PsAccess struct { - IDProfile int32 `gorm:"column:id_profile;primaryKey" json:"id_profile"` - IDAuthorizationRole int32 `gorm:"column:id_authorization_role;primaryKey" json:"id_authorization_role"` -} - -// TableName PsAccess's table name -func (*PsAccess) TableName() string { - return TableNamePsAccess -} - -var PsAccessCols = struct { - IDProfile gormcol.Field - IDAuthorizationRole gormcol.Field -}{ - IDProfile: gormcol.Field{Column: "id_profile"}, - IDAuthorizationRole: gormcol.Field{Column: "id_authorization_role"}, -} diff --git a/app/model/dbmodel/ps_module_shop.go b/app/model/dbmodel/ps_module_shop.go new file mode 100644 index 0000000..74848fc --- /dev/null +++ b/app/model/dbmodel/ps_module_shop.go @@ -0,0 +1,31 @@ +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. +// Code generated by gorm.io/gen. DO NOT EDIT. + +package dbmodel + +import "git.ma-al.com/goc_marek/gormcol" + +const TableNamePsModuleShop = "ps_module_shop" + +// PsModuleShop mapped from table +type PsModuleShop struct { + IDModule int32 `gorm:"column:id_module;primaryKey" json:"id_module"` + IDShop int32 `gorm:"column:id_shop;primaryKey;index:id_shop,priority:1" json:"id_shop"` + EnableDevice bool `gorm:"column:enable_device;not null;default:7" json:"enable_device"` +} + +// TableName PsModuleShop's table name +func (*PsModuleShop) TableName() string { + return TableNamePsModuleShop +} + +var PsModuleShopCols = struct { + IDModule gormcol.Field + IDShop gormcol.Field + EnableDevice gormcol.Field +}{ + IDModule: gormcol.Field{Table: (PsModuleShop{}).TableName(), Column: "id_module"}, + IDShop: gormcol.Field{Table: (PsModuleShop{}).TableName(), Column: "id_shop"}, + EnableDevice: gormcol.Field{Table: (PsModuleShop{}).TableName(), Column: "enable_device"}, +} diff --git a/gencols.go b/gencols.go index aabb0b9..0b56ab1 100644 --- a/gencols.go +++ b/gencols.go @@ -175,7 +175,7 @@ func generateColsVarBlock(si *structInfo) string { } b.WriteString("}{\n") for _, f := range si.Fields { - b.WriteString(fmt.Sprintf("\t%s: gormcol.Field{Column: %q},\n", f.GoName, f.ColName)) + b.WriteString(fmt.Sprintf("\t%s: gormcol.Field{Table: (%s{}).TableName(), Column: %q},\n", f.GoName, si.Name, f.ColName)) } b.WriteString("}\n") return b.String() diff --git a/gormcol b/gormcol index f667942..a2fdf8d 100755 Binary files a/gormcol and b/gormcol differ diff --git a/gormcol.go b/gormcol.go index 40ea9a8..2909932 100644 --- a/gormcol.go +++ b/gormcol.go @@ -9,26 +9,19 @@ // IDProfile gormcol.Field // IDAuthorizationRole gormcol.Field // }{ -// IDProfile: gormcol.Field{Column: "id_profile"}, -// IDAuthorizationRole: gormcol.Field{Column: "id_authorization_role"}, +// IDProfile: gormcol.Field{Table: (PsAccess{}).TableName(), Column: "id_profile"}, +// IDAuthorizationRole: gormcol.Field{Table: (PsAccess{}).TableName(), 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. +// 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. -// -// Example: -// -// gormcol.Column(dbmodel.PsAccessCols.IDAuthorizationRole) // "id_authorization_role" func Column(f Field) string { return f.Column }