github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_organization.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 // SysOrganizationDao is the data access object for table sys_organization. 18 type SysOrganizationDao 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 SysOrganizationColumns // columns contains all the column names of Table for convenient usage. 22 } 23 24 // SysOrganizationColumns defines and stores column names for table sys_organization. 25 type SysOrganizationColumns struct { 26 Id string // 27 Name string // 名称 28 ParentId string // 父级ID 29 CascadeDeep string // 级联深度 30 Description string // 描述 31 } 32 33 // sysOrganizationColumns holds the columns for table sys_organization. 34 var sysOrganizationColumns = SysOrganizationColumns{ 35 Id: "id", 36 Name: "name", 37 ParentId: "parent_id", 38 CascadeDeep: "cascade_deep", 39 Description: "description", 40 } 41 42 // NewSysOrganizationDao creates and returns a new DAO object for table data access. 43 func NewSysOrganizationDao(proxy ...dao_interface.IDao) *SysOrganizationDao { 44 var dao *SysOrganizationDao 45 if len(proxy) > 0 { 46 dao = &SysOrganizationDao{ 47 group: proxy[0].Group(), 48 table: proxy[0].Table(), 49 columns: sysOrganizationColumns, 50 } 51 return dao 52 } 53 54 return &SysOrganizationDao{ 55 group: "default", 56 table: "sys_organization", 57 columns: sysOrganizationColumns, 58 } 59 } 60 61 // DB retrieves and returns the underlying raw database management object of current DAO. 62 func (dao *SysOrganizationDao) DB() gdb.DB { 63 return g.DB(dao.group) 64 } 65 66 // Table returns the table name of current dao. 67 func (dao *SysOrganizationDao) Table() string { 68 return dao.table 69 } 70 71 // Group returns the configuration group name of database of current dao. 72 func (dao *SysOrganizationDao) Group() string { 73 return dao.group 74 } 75 76 // Columns returns all column names of current dao. 77 func (dao *SysOrganizationDao) Columns() SysOrganizationColumns { 78 return dao.columns 79 } 80 81 // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 82 func (dao *SysOrganizationDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model { 83 return dao.DaoConfig(ctx, cacheOption...).Model 84 } 85 86 func (dao *SysOrganizationDao) DaoConfig(ctx context.Context, cacheOption ...*gdb.CacheOption) dao_interface.DaoConfig { 87 daoConfig := dao_interface.DaoConfig{ 88 Dao: dao, 89 DB: dao.DB(), 90 Table: dao.table, 91 Group: dao.group, 92 Model: dao.DB().Model(dao.Table()).Safe().Ctx(ctx), 93 } 94 95 if len(cacheOption) == 0 { 96 daoConfig.CacheOption = daoctl.MakeDaoCache(dao.Table()) 97 daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption) 98 } else { 99 if cacheOption[0] != nil { 100 daoConfig.CacheOption = cacheOption[0] 101 daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption) 102 } 103 } 104 105 daoConfig.Model = daoctl.RegisterDaoHook(daoConfig.Model) 106 107 return daoConfig 108 } 109 110 // Transaction wraps the transaction logic using function f. 111 // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 112 // It commits the transaction and returns nil if function f returns nil. 113 // 114 // Note that, you should not Commit or Rollback the transaction in function f 115 // as it is automatically handled by this function. 116 func (dao *SysOrganizationDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 117 return dao.Ctx(ctx).Transaction(ctx, f) 118 }