github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_permission.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  // SysPermissionDao is the data access object for table sys_permission.
    18  type SysPermissionDao 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 SysPermissionColumns // columns contains all the column names of Table for convenient usage.
    22  }
    23  
    24  // SysPermissionColumns defines and stores column names for table sys_permission.
    25  type SysPermissionColumns struct {
    26  	Id          string // ID
    27  	ParentId    string // 父级ID
    28  	Name        string // 名称
    29  	Description string // 描述
    30  	Identifier  string // 标识符
    31  	Type        string // 类型:1api,2menu
    32  	MatchMode   string // 匹配模式:ID:0,标识符:1
    33  	IsShow      string // 是否显示:0不显示 1显示
    34  	Sort        string // 排序
    35  	CreatedAt   string //
    36  	UpdatedAt   string //
    37  }
    38  
    39  // sysPermissionColumns holds the columns for table sys_permission.
    40  var sysPermissionColumns = SysPermissionColumns{
    41  	Id:          "id",
    42  	ParentId:    "parent_id",
    43  	Name:        "name",
    44  	Description: "description",
    45  	Identifier:  "identifier",
    46  	Type:        "type",
    47  	MatchMode:   "match_mode",
    48  	IsShow:      "is_show",
    49  	Sort:        "sort",
    50  	CreatedAt:   "created_at",
    51  	UpdatedAt:   "updated_at",
    52  }
    53  
    54  // NewSysPermissionDao creates and returns a new DAO object for table data access.
    55  func NewSysPermissionDao(proxy ...dao_interface.IDao) *SysPermissionDao {
    56  	var dao *SysPermissionDao
    57  	if len(proxy) > 0 {
    58  		dao = &SysPermissionDao{
    59  			group:   proxy[0].Group(),
    60  			table:   proxy[0].Table(),
    61  			columns: sysPermissionColumns,
    62  		}
    63  		return dao
    64  	}
    65  
    66  	return &SysPermissionDao{
    67  		group:   "default",
    68  		table:   "sys_permission",
    69  		columns: sysPermissionColumns,
    70  	}
    71  }
    72  
    73  // DB retrieves and returns the underlying raw database management object of current DAO.
    74  func (dao *SysPermissionDao) DB() gdb.DB {
    75  	return g.DB(dao.group)
    76  }
    77  
    78  // Table returns the table name of current dao.
    79  func (dao *SysPermissionDao) Table() string {
    80  	return dao.table
    81  }
    82  
    83  // Group returns the configuration group name of database of current dao.
    84  func (dao *SysPermissionDao) Group() string {
    85  	return dao.group
    86  }
    87  
    88  // Columns returns all column names of current dao.
    89  func (dao *SysPermissionDao) Columns() SysPermissionColumns {
    90  	return dao.columns
    91  }
    92  
    93  // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
    94  func (dao *SysPermissionDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model {
    95  	return dao.DaoConfig(ctx, cacheOption...).Model
    96  }
    97  
    98  func (dao *SysPermissionDao) DaoConfig(ctx context.Context, cacheOption ...*gdb.CacheOption) dao_interface.DaoConfig {
    99  	daoConfig := dao_interface.DaoConfig{
   100  		Dao:   dao,
   101  		DB:    dao.DB(),
   102  		Table: dao.table,
   103  		Group: dao.group,
   104  		Model: dao.DB().Model(dao.Table()).Safe().Ctx(ctx),
   105  	}
   106  
   107  	if len(cacheOption) == 0 {
   108  		daoConfig.CacheOption = daoctl.MakeDaoCache(dao.Table())
   109  		daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   110  	} else {
   111  		if cacheOption[0] != nil {
   112  			daoConfig.CacheOption = cacheOption[0]
   113  			daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   114  		}
   115  	}
   116  
   117  	daoConfig.Model = daoctl.RegisterDaoHook(daoConfig.Model)
   118  
   119  	return daoConfig
   120  }
   121  
   122  // Transaction wraps the transaction logic using function f.
   123  // It rollbacks the transaction and returns the error from function f if it returns non-nil error.
   124  // It commits the transaction and returns nil if function f returns nil.
   125  //
   126  // Note that, you should not Commit or Rollback the transaction in function f
   127  // as it is automatically handled by this function.
   128  func (dao *SysPermissionDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
   129  	return dao.Ctx(ctx).Transaction(ctx, f)
   130  }