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