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