github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_menu.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  // SysMenuDao is the data access object for table sys_menu.
    18  type SysMenuDao 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 SysMenuColumns // columns contains all the column names of Table for convenient usage.
    22  }
    23  
    24  // SysMenuColumns defines and stores column names for table sys_menu.
    25  type SysMenuColumns struct {
    26  	Id           string // ID
    27  	Path         string // 路径
    28  	Name         string // 名称
    29  	Redirect     string // 跳转
    30  	Title        string // 标题
    31  	Icon         string // 图标
    32  	Component    string // 组件
    33  	ParentId     string // 所属父级
    34  	Sort         string // 排序
    35  	State        string // 状态:0隐藏,1显示
    36  	Description  string // 描述
    37  	CreatedAt    string //
    38  	UpdatedAt    string //
    39  	IconUrl      string // 图标URL
    40  	RedirectType string // 跳转类型:1当前页面打开、 2新的标签页打开
    41  	Type         string // 类型:1菜单、2按钮
    42  }
    43  
    44  // sysMenuColumns holds the columns for table sys_menu.
    45  var sysMenuColumns = SysMenuColumns{
    46  	Id:           "id",
    47  	Path:         "path",
    48  	Name:         "name",
    49  	Redirect:     "redirect",
    50  	Title:        "title",
    51  	Icon:         "icon",
    52  	Component:    "component",
    53  	ParentId:     "parent_id",
    54  	Sort:         "sort",
    55  	State:        "state",
    56  	Description:  "description",
    57  	CreatedAt:    "created_at",
    58  	UpdatedAt:    "updated_at",
    59  	IconUrl:      "icon_url",
    60  	RedirectType: "redirect_type",
    61  	Type:         "type",
    62  }
    63  
    64  // NewSysMenuDao creates and returns a new DAO object for table data access.
    65  func NewSysMenuDao(proxy ...dao_interface.IDao) *SysMenuDao {
    66  	var dao *SysMenuDao
    67  	if len(proxy) > 0 {
    68  		dao = &SysMenuDao{
    69  			group:   proxy[0].Group(),
    70  			table:   proxy[0].Table(),
    71  			columns: sysMenuColumns,
    72  		}
    73  		return dao
    74  	}
    75  
    76  	return &SysMenuDao{
    77  		group:   "default",
    78  		table:   "sys_menu",
    79  		columns: sysMenuColumns,
    80  	}
    81  }
    82  
    83  // DB retrieves and returns the underlying raw database management object of current DAO.
    84  func (dao *SysMenuDao) DB() gdb.DB {
    85  	return g.DB(dao.group)
    86  }
    87  
    88  // Table returns the table name of current dao.
    89  func (dao *SysMenuDao) Table() string {
    90  	return dao.table
    91  }
    92  
    93  // Group returns the configuration group name of database of current dao.
    94  func (dao *SysMenuDao) Group() string {
    95  	return dao.group
    96  }
    97  
    98  // Columns returns all column names of current dao.
    99  func (dao *SysMenuDao) Columns() SysMenuColumns {
   100  	return dao.columns
   101  }
   102  
   103  // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
   104  func (dao *SysMenuDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model {
   105  	return dao.DaoConfig(ctx, cacheOption...).Model
   106  }
   107  
   108  func (dao *SysMenuDao) DaoConfig(ctx context.Context, cacheOption ...*gdb.CacheOption) dao_interface.DaoConfig {
   109  	daoConfig := dao_interface.DaoConfig{
   110  		Dao:   dao,
   111  		DB:    dao.DB(),
   112  		Table: dao.table,
   113  		Group: dao.group,
   114  		Model: dao.DB().Model(dao.Table()).Safe().Ctx(ctx),
   115  	}
   116  
   117  	if len(cacheOption) == 0 {
   118  		daoConfig.CacheOption = daoctl.MakeDaoCache(dao.Table())
   119  		daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   120  	} else {
   121  		if cacheOption[0] != nil {
   122  			daoConfig.CacheOption = cacheOption[0]
   123  			daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   124  		}
   125  	}
   126  
   127  	daoConfig.Model = daoctl.RegisterDaoHook(daoConfig.Model)
   128  
   129  	return daoConfig
   130  }
   131  
   132  // Transaction wraps the transaction logic using function f.
   133  // It rollbacks the transaction and returns the error from function f if it returns non-nil error.
   134  // It commits the transaction and returns nil if function f returns nil.
   135  //
   136  // Note that, you should not Commit or Rollback the transaction in function f
   137  // as it is automatically handled by this function.
   138  func (dao *SysMenuDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
   139  	return dao.Ctx(ctx).Transaction(ctx, f)
   140  }