github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_file.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 // SysFileDao is the data access object for table sys_file. 18 type SysFileDao 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 SysFileColumns // columns contains all the column names of Table for convenient usage. 22 } 23 24 // SysFileColumns defines and stores column names for table sys_file. 25 type SysFileColumns struct { 26 Id string // 自增ID 27 Name string // 文件名称 28 Src string // 存储路径 29 Url string // URL地址 30 Ext string // 扩展名 31 Size string // 文件大小 32 Category string // 文件分类 33 UserId string // 用户ID 34 UnionMainId string // 关联主体ID 35 CreatedAt string // 36 UpdatedAt string // 37 LocalPath string // 本地路径 38 } 39 40 // sysFileColumns holds the columns for table sys_file. 41 var sysFileColumns = SysFileColumns{ 42 Id: "id", 43 Name: "name", 44 Src: "src", 45 Url: "url", 46 Ext: "ext", 47 Size: "size", 48 Category: "category", 49 UserId: "user_id", 50 UnionMainId: "union_main_id", 51 CreatedAt: "created_at", 52 UpdatedAt: "updated_at", 53 LocalPath: "local_path", 54 } 55 56 // NewSysFileDao creates and returns a new DAO object for table data access. 57 func NewSysFileDao(proxy ...dao_interface.IDao) *SysFileDao { 58 var dao *SysFileDao 59 if len(proxy) > 0 { 60 dao = &SysFileDao{ 61 group: proxy[0].Group(), 62 table: proxy[0].Table(), 63 columns: sysFileColumns, 64 } 65 return dao 66 } 67 68 return &SysFileDao{ 69 group: "default", 70 table: "sys_file", 71 columns: sysFileColumns, 72 } 73 } 74 75 // DB retrieves and returns the underlying raw database management object of current DAO. 76 func (dao *SysFileDao) DB() gdb.DB { 77 return g.DB(dao.group) 78 } 79 80 // Table returns the table name of current dao. 81 func (dao *SysFileDao) Table() string { 82 return dao.table 83 } 84 85 // Group returns the configuration group name of database of current dao. 86 func (dao *SysFileDao) Group() string { 87 return dao.group 88 } 89 90 // Columns returns all column names of current dao. 91 func (dao *SysFileDao) Columns() SysFileColumns { 92 return dao.columns 93 } 94 95 // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. 96 func (dao *SysFileDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model { 97 return dao.DaoConfig(ctx, cacheOption...).Model 98 } 99 100 func (dao *SysFileDao) DaoConfig(ctx context.Context, cacheOption ...*gdb.CacheOption) dao_interface.DaoConfig { 101 daoConfig := dao_interface.DaoConfig{ 102 Dao: dao, 103 DB: dao.DB(), 104 Table: dao.table, 105 Group: dao.group, 106 Model: dao.DB().Model(dao.Table()).Safe().Ctx(ctx), 107 } 108 109 if len(cacheOption) == 0 { 110 daoConfig.CacheOption = daoctl.MakeDaoCache(dao.Table()) 111 daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption) 112 } else { 113 if cacheOption[0] != nil { 114 daoConfig.CacheOption = cacheOption[0] 115 daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption) 116 } 117 } 118 119 daoConfig.Model = daoctl.RegisterDaoHook(daoConfig.Model) 120 121 return daoConfig 122 } 123 124 // Transaction wraps the transaction logic using function f. 125 // It rollbacks the transaction and returns the error from function f if it returns non-nil error. 126 // It commits the transaction and returns nil if function f returns nil. 127 // 128 // Note that, you should not Commit or Rollback the transaction in function f 129 // as it is automatically handled by this function. 130 func (dao *SysFileDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { 131 return dao.Ctx(ctx).Transaction(ctx, f) 132 }