github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_casbin.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  // SysCasbinDao is the data access object for table sys_casbin.
    18  type SysCasbinDao 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 SysCasbinColumns // columns contains all the column names of Table for convenient usage.
    22  }
    23  
    24  // SysCasbinColumns defines and stores column names for table sys_casbin.
    25  type SysCasbinColumns struct {
    26  	Ptype string //
    27  	V0    string //
    28  	V1    string //
    29  	V2    string //
    30  	V3    string //
    31  	V4    string //
    32  	V5    string //
    33  }
    34  
    35  // sysCasbinColumns holds the columns for table sys_casbin.
    36  var sysCasbinColumns = SysCasbinColumns{
    37  	Ptype: "ptype",
    38  	V0:    "v0",
    39  	V1:    "v1",
    40  	V2:    "v2",
    41  	V3:    "v3",
    42  	V4:    "v4",
    43  	V5:    "v5",
    44  }
    45  
    46  // NewSysCasbinDao creates and returns a new DAO object for table data access.
    47  func NewSysCasbinDao(proxy ...dao_interface.IDao) *SysCasbinDao {
    48  	var dao *SysCasbinDao
    49  	if len(proxy) > 0 {
    50  		dao = &SysCasbinDao{
    51  			group:   proxy[0].Group(),
    52  			table:   proxy[0].Table(),
    53  			columns: sysCasbinColumns,
    54  		}
    55  		return dao
    56  	}
    57  
    58  	return &SysCasbinDao{
    59  		group:   "default",
    60  		table:   "sys_casbin",
    61  		columns: sysCasbinColumns,
    62  	}
    63  }
    64  
    65  // DB retrieves and returns the underlying raw database management object of current DAO.
    66  func (dao *SysCasbinDao) DB() gdb.DB {
    67  	return g.DB(dao.group)
    68  }
    69  
    70  // Table returns the table name of current dao.
    71  func (dao *SysCasbinDao) Table() string {
    72  	return dao.table
    73  }
    74  
    75  // Group returns the configuration group name of database of current dao.
    76  func (dao *SysCasbinDao) Group() string {
    77  	return dao.group
    78  }
    79  
    80  // Columns returns all column names of current dao.
    81  func (dao *SysCasbinDao) Columns() SysCasbinColumns {
    82  	return dao.columns
    83  }
    84  
    85  // Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
    86  func (dao *SysCasbinDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model {
    87  	return dao.DaoConfig(ctx, cacheOption...).Model
    88  }
    89  
    90  func (dao *SysCasbinDao) DaoConfig(ctx context.Context, cacheOption ...*gdb.CacheOption) dao_interface.DaoConfig {
    91  	daoConfig := dao_interface.DaoConfig{
    92  		Dao:   dao,
    93  		DB:    dao.DB(),
    94  		Table: dao.table,
    95  		Group: dao.group,
    96  		Model: dao.DB().Model(dao.Table()).Safe().Ctx(ctx),
    97  	}
    98  
    99  	if len(cacheOption) == 0 {
   100  		daoConfig.CacheOption = daoctl.MakeDaoCache(dao.Table())
   101  		daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   102  	} else {
   103  		if cacheOption[0] != nil {
   104  			daoConfig.CacheOption = cacheOption[0]
   105  			daoConfig.Model = daoConfig.Model.Cache(*daoConfig.CacheOption)
   106  		}
   107  	}
   108  
   109  	daoConfig.Model = daoctl.RegisterDaoHook(daoConfig.Model)
   110  
   111  	return daoConfig
   112  }
   113  
   114  // Transaction wraps the transaction logic using function f.
   115  // It rollbacks the transaction and returns the error from function f if it returns non-nil error.
   116  // It commits the transaction and returns nil if function f returns nil.
   117  //
   118  // Note that, you should not Commit or Rollback the transaction in function f
   119  // as it is automatically handled by this function.
   120  func (dao *SysCasbinDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
   121  	return dao.Ctx(ctx).Transaction(ctx, f)
   122  }