github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_user.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  // SysUserDao is the data access object for table sys_user.
    18  type SysUserDao 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 SysUserColumns // columns contains all the column names of Table for convenient usage.
    22  }
    23  
    24  // SysUserColumns defines and stores column names for table sys_user.
    25  type SysUserColumns struct {
    26  	Id        string //
    27  	Username  string // 账号
    28  	Password  string // 密码
    29  	State     string // 状态:0未激活、1正常、-1封号、-2异常、-3已注销
    30  	Type      string // 用户类型:0匿名、1用户、2微商、4商户、8广告主、16服务商、32运营中心、64后台
    31  	Mobile    string // 手机号
    32  	CreatedAt string //
    33  	UpdatedAt string //
    34  	DeletedAt string //
    35  	Email     string // 邮箱
    36  }
    37  
    38  // sysUserColumns holds the columns for table sys_user.
    39  var sysUserColumns = SysUserColumns{
    40  	Id:        "id",
    41  	Username:  "username",
    42  	Password:  "password",
    43  	State:     "state",
    44  	Type:      "type",
    45  	Mobile:    "mobile",
    46  	CreatedAt: "created_at",
    47  	UpdatedAt: "updated_at",
    48  	DeletedAt: "deleted_at",
    49  	Email:     "email",
    50  }
    51  
    52  // NewSysUserDao creates and returns a new DAO object for table data access.
    53  func NewSysUserDao(proxy ...dao_interface.IDao) *SysUserDao {
    54  	var dao *SysUserDao
    55  	if len(proxy) > 0 {
    56  		dao = &SysUserDao{
    57  			group:   proxy[0].Group(),
    58  			table:   proxy[0].Table(),
    59  			columns: sysUserColumns,
    60  		}
    61  		return dao
    62  	}
    63  
    64  	return &SysUserDao{
    65  		group:   "default",
    66  		table:   "sys_user",
    67  		columns: sysUserColumns,
    68  	}
    69  }
    70  
    71  // DB retrieves and returns the underlying raw database management object of current DAO.
    72  func (dao *SysUserDao) DB() gdb.DB {
    73  	return g.DB(dao.group)
    74  }
    75  
    76  // Table returns the table name of current dao.
    77  func (dao *SysUserDao) Table() string {
    78  	return dao.table
    79  }
    80  
    81  // Group returns the configuration group name of database of current dao.
    82  func (dao *SysUserDao) Group() string {
    83  	return dao.group
    84  }
    85  
    86  // Columns returns all column names of current dao.
    87  func (dao *SysUserDao) Columns() SysUserColumns {
    88  	return dao.columns
    89  }
    90  
    91  // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
    92  func (dao *SysUserDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model {
    93  	return dao.DaoConfig(ctx, cacheOption...).Model
    94  }
    95  
    96  func (dao *SysUserDao) DaoConfig(ctx context.Context, cacheOption ...*gdb.CacheOption) dao_interface.DaoConfig {
    97  	daoConfig := dao_interface.DaoConfig{
    98  		Dao:   dao,
    99  		DB:    dao.DB(),
   100  		Table: dao.table,
   101  		Group: dao.group,
   102  		Model: dao.DB().Model(dao.Table()).Safe().Ctx(ctx),
   103  	}
   104  
   105  	if len(cacheOption) == 0 {
   106  		daoConfig.CacheOption = daoctl.MakeDaoCache(dao.Table())
   107  		daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   108  	} else {
   109  		if cacheOption[0] != nil {
   110  			daoConfig.CacheOption = cacheOption[0]
   111  			daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   112  		}
   113  	}
   114  
   115  	daoConfig.Model = daoctl.RegisterDaoHook(daoConfig.Model)
   116  
   117  	return daoConfig
   118  }
   119  
   120  // Transaction wraps the transaction logic using function f.
   121  // It rollbacks the transaction and returns the error from function f if it returns non-nil error.
   122  // It commits the transaction and returns nil if function f returns nil.
   123  //
   124  // Note that, you should not Commit or Rollback the transaction in function f
   125  // as it is automatically handled by this function.
   126  func (dao *SysUserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
   127  	return dao.Ctx(ctx).Transaction(ctx, f)
   128  }