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