github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_role.go (about) 1 // ========================================================================== 2 // Code generated by GoFrame CLI tool. DO NOT EDIT. 3 // ========================================================================== 4 5 package internal 6 7 import ( 8 "context" 9 10 "github.com/kysion/base-library/utility/daoctl" 11 "github.com/kysion/base-library/utility/daoctl/dao_interface" 12 13 "github.com/gogf/gf/v2/database/gdb" 14 "github.com/gogf/gf/v2/frame/g" 15 ) 16 17 // SysRoleDao is the data access object for table sys_role. 18 type SysRoleDao struct { 19 table string // table is the underlying table name of the DAO. 20 group string // group is the database configuration group name of current DAO. 21 columns SysRoleColumns // columns contains all the column names of Table for convenient usage. 22 } 23 24 // SysRoleColumns defines and stores column names for table sys_role. 25 type SysRoleColumns struct { 26 Id string // 27 Name string // 名称 28 Description string // 描述 29 IsSystem string // 是否默认角色,true仅能修改名称,不允许删除和修改 30 UpdatedAt string // 31 CreatedAt string // 32 UnionMainId string // 主体id 33 } 34 35 // sysRoleColumns holds the columns for table sys_role. 36 var sysRoleColumns = SysRoleColumns{ 37 Id: "id", 38 Name: "name", 39 Description: "description", 40 IsSystem: "is_system", 41 UpdatedAt: "updated_at", 42 CreatedAt: "created_at", 43 UnionMainId: "union_main_id", 44 } 45 46 // NewSysRoleDao creates and returns a new DAO object for table data access. 47 func NewSysRoleDao(proxy ...dao_interface.IDao) *SysRoleDao { 48 var dao *SysRoleDao 49 if len(proxy) > 0 { 50 dao = &SysRoleDao{ 51 group: proxy[0].Group(), 52 table: proxy[0].Table(), 53 columns: sysRoleColumns, 54 } 55 return dao 56 } 57 58 return &SysRoleDao{ 59 group: "default", 60 table: "sys_role", 61 columns: sysRoleColumns, 62 } 63 } 64 65 // DB retrieves and returns the underlying raw database management object of current DAO. 66 func (dao *SysRoleDao) DB() gdb.DB { 67 return g.DB(dao.group) 68 } 69 70 // Table returns the table name of current dao. 71 func (dao *SysRoleDao) Table() string { 72 return dao.table 73 } 74 75 // Group returns the configuration group name of database of current dao. 76 func (dao *SysRoleDao) Group() string { 77 return dao.group 78 } 79 80 // Columns returns all column names of current dao. 81 func (dao *SysRoleDao) Columns() SysRoleColumns { 82 return dao.columns 83 } 84 85 // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 86 func (dao *SysRoleDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model { 87 return dao.DaoConfig(ctx, cacheOption...).Model 88 } 89 90 func (dao *SysRoleDao) DaoConfig(ctx context.Context, cacheOption ...*gdb.CacheOption) dao_interface.DaoConfig { 91 daoConfig := dao_interface.DaoConfig{ 92 Dao: dao, 93 DB: dao.DB(), 94 Table: dao.table, 95 Group: dao.group, 96 Model: dao.DB().Model(dao.Table()).Safe().Ctx(ctx), 97 } 98 99 if len(cacheOption) == 0 { 100 daoConfig.CacheOption = daoctl.MakeDaoCache(dao.Table()) 101 daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption) 102 } else { 103 if cacheOption[0] != nil { 104 daoConfig.CacheOption = cacheOption[0] 105 daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption) 106 } 107 } 108 109 daoConfig.Model = daoctl.RegisterDaoHook(daoConfig.Model) 110 111 return daoConfig 112 } 113 114 // Transaction wraps the transaction logic using function f. 115 // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 116 // It commits the transaction and returns nil if function f returns nil. 117 // 118 // Note that, you should not Commit or Rollback the transaction in function f 119 // as it is automatically handled by this function. 120 func (dao *SysRoleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 121 return dao.Ctx(ctx).Transaction(ctx, f) 122 }