github.com/SupenBysz/gf-admin-community@v0.7.4/sys_model/sys_dao/internal/sys_area.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  // SysAreaDao is the data access object for table sys_area.
    18  type SysAreaDao 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 SysAreaColumns // columns contains all the column names of Table for convenient usage.
    22  }
    23  
    24  // SysAreaColumns defines and stores column names for table sys_area.
    25  type SysAreaColumns struct {
    26  	Id            string // ID
    27  	AreaCode      string // 地区编码
    28  	AreaName      string // 地区名称
    29  	Level         string // 1区县district、2市city、4省份province、8大区region、16全国nation
    30  	CityCode      string // 城市编码
    31  	LatLongCenter string // 城市中心点(即经纬度)
    32  	ParentId      string // 地区父节点
    33  }
    34  
    35  // sysAreaColumns holds the columns for table sys_area.
    36  var sysAreaColumns = SysAreaColumns{
    37  	Id:            "id",
    38  	AreaCode:      "area_code",
    39  	AreaName:      "area_name",
    40  	Level:         "level",
    41  	CityCode:      "city_code",
    42  	LatLongCenter: "lat_long_center",
    43  	ParentId:      "parent_id",
    44  }
    45  
    46  // NewSysAreaDao creates and returns a new DAO object for table data access.
    47  func NewSysAreaDao(proxy ...dao_interface.IDao) *SysAreaDao {
    48  	var dao *SysAreaDao
    49  	if len(proxy) > 0 {
    50  		dao = &SysAreaDao{
    51  			group:   proxy[0].Group(),
    52  			table:   proxy[0].Table(),
    53  			columns: sysAreaColumns,
    54  		}
    55  		return dao
    56  	}
    57  
    58  	return &SysAreaDao{
    59  		group:   "default",
    60  		table:   "sys_area",
    61  		columns: sysAreaColumns,
    62  	}
    63  }
    64  
    65  // DB retrieves and returns the underlying raw database management object of current DAO.
    66  func (dao *SysAreaDao) DB() gdb.DB {
    67  	return g.DB(dao.group)
    68  }
    69  
    70  // Table returns the table name of current dao.
    71  func (dao *SysAreaDao) Table() string {
    72  	return dao.table
    73  }
    74  
    75  // Group returns the configuration group name of database of current dao.
    76  func (dao *SysAreaDao) Group() string {
    77  	return dao.group
    78  }
    79  
    80  // Columns returns all column names of current dao.
    81  func (dao *SysAreaDao) Columns() SysAreaColumns {
    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 *SysAreaDao) Ctx(ctx context.Context, cacheOption ...*gdb.CacheOption) *gdb.Model {
    87  	return dao.DaoConfig(ctx, cacheOption...).Model
    88  }
    89  
    90  func (dao *SysAreaDao) 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 *SysAreaDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
   121  	return dao.Ctx(ctx).Transaction(ctx, f)
   122  }