github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_invite.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  // SysInviteDao is the data access object for table sys_invite.
    18  type SysInviteDao 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 SysInviteColumns // columns contains all the column names of Table for convenient usage.
    22  }
    23  
    24  // SysInviteColumns defines and stores column names for table sys_invite.
    25  type SysInviteColumns struct {
    26  	Id             string // ID
    27  	UserId         string // 用户ID, 也就是邀约人ID
    28  	Value          string // 邀约码背后的关联业务Json数据,
    29  	ExpireAt       string // 邀约码的过期失效
    30  	ActivateNumber string // 邀约码的激活次数限制
    31  	State          string // 状态: 0失效、1正常
    32  	Type           string // 类型: 1注册、2加入团队、4加入角色 (复合类型)
    33  	CreatedAt      string //
    34  }
    35  
    36  // sysInviteColumns holds the columns for table sys_invite.
    37  var sysInviteColumns = SysInviteColumns{
    38  	Id:             "id",
    39  	UserId:         "user_id",
    40  	Value:          "value",
    41  	ExpireAt:       "expire_at",
    42  	ActivateNumber: "activate_number",
    43  	State:          "state",
    44  	Type:           "type",
    45  	CreatedAt:      "created_at",
    46  }
    47  
    48  // NewSysInviteDao creates and returns a new DAO object for table data access.
    49  func NewSysInviteDao(proxy ...dao_interface.IDao) *SysInviteDao {
    50  	var dao *SysInviteDao
    51  	if len(proxy) > 0 {
    52  		dao = &SysInviteDao{
    53  			group:   proxy[0].Group(),
    54  			table:   proxy[0].Table(),
    55  			columns: sysInviteColumns,
    56  		}
    57  		return dao
    58  	}
    59  
    60  	return &SysInviteDao{
    61  		group:   "default",
    62  		table:   "sys_invite",
    63  		columns: sysInviteColumns,
    64  	}
    65  }
    66  
    67  // DB retrieves and returns the underlying raw database management object of current DAO.
    68  func (dao *SysInviteDao) DB() gdb.DB {
    69  	return g.DB(dao.group)
    70  }
    71  
    72  // Table returns the table name of current dao.
    73  func (dao *SysInviteDao) Table() string {
    74  	return dao.table
    75  }
    76  
    77  // Group returns the configuration group name of database of current dao.
    78  func (dao *SysInviteDao) Group() string {
    79  	return dao.group
    80  }
    81  
    82  // Columns returns all column names of current dao.
    83  func (dao *SysInviteDao) Columns() SysInviteColumns {
    84  	return dao.columns
    85  }
    86  
    87  // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
    88  func (dao *SysInviteDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model {
    89  	return dao.DaoConfig(ctx, cacheOption...).Model
    90  }
    91  
    92  func (dao *SysInviteDao) DaoConfig(ctx context.Context, cacheOption ...*gdb.CacheOption) dao_interface.DaoConfig {
    93  	daoConfig := dao_interface.DaoConfig{
    94  		Dao:   dao,
    95  		DB:    dao.DB(),
    96  		Table: dao.table,
    97  		Group: dao.group,
    98  		Model: dao.DB().Model(dao.Table()).Safe().Ctx(ctx),
    99  	}
   100  
   101  	if len(cacheOption) == 0 {
   102  		daoConfig.CacheOption = daoctl.MakeDaoCache(dao.Table())
   103  		daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   104  	} else {
   105  		if cacheOption[0] != nil {
   106  			daoConfig.CacheOption = cacheOption[0]
   107  			daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   108  		}
   109  	}
   110  
   111  	daoConfig.Model = daoctl.RegisterDaoHook(daoConfig.Model)
   112  
   113  	return daoConfig
   114  }
   115  
   116  // Transaction wraps the transaction logic using function f.
   117  // It rollbacks the transaction and returns the error from function f if it returns non-nil error.
   118  // It commits the transaction and returns nil if function f returns nil.
   119  //
   120  // Note that, you should not Commit or Rollback the transaction in function f
   121  // as it is automatically handled by this function.
   122  func (dao *SysInviteDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
   123  	return dao.Ctx(ctx).Transaction(ctx, f)
   124  }