| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- // ==========================================================================
- // This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
- // ==========================================================================
- package internal
- import (
- "context"
- "database/sql"
- "github.com/gogf/gf/database/gdb"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/frame/gmvc"
- "time"
- "dashoo.cn/micro/app/model"
- )
- // SysGroupRoleDao is the manager for logic model data accessing
- // and custom defined data operations functions management.
- type SysGroupRoleDao struct {
- gmvc.M
- DB gdb.DB
- Table string
- Columns sysGroupRoleColumns
- }
- // SysGroupRoleColumns defines and stores column names for table sys_group_role.
- type sysGroupRoleColumns struct {
- GroupId string // 用户组ID
- RoleId string // 角色ID
- }
- var (
- // SysGroupRole is globally public accessible object for table sys_group_role operations.
- SysGroupRole = SysGroupRoleDao{
- M: g.DB("default").Model("sys_group_role").Safe(),
- DB: g.DB("default"),
- Table: "sys_group_role",
- Columns: sysGroupRoleColumns{
- GroupId: "group_id",
- RoleId: "role_id",
- },
- }
- )
- func NewSysGroupRoleDao(tenant string) SysGroupRoleDao {
- var dao SysGroupRoleDao
- dao = SysGroupRoleDao{
- M: g.DB(tenant).Model("sys_group_role").Safe(),
- DB: g.DB(tenant),
- Table: "sys_group_role",
- Columns: sysGroupRoleColumns{
- GroupId: "group_id",
- RoleId: "role_id",
- },
- }
- return dao
- }
- // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
- // of current DB object and with given context in it.
- // Note that this returned DB object can be used only once, so do not assign it to
- // a global or package variable for long using.
- func (d *SysGroupRoleDao) Ctx(ctx context.Context) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Ctx(ctx)}
- }
- // As sets an alias name for current table.
- func (d *SysGroupRoleDao) As(as string) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.As(as)}
- }
- // TX sets the transaction for current operation.
- func (d *SysGroupRoleDao) TX(tx *gdb.TX) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.TX(tx)}
- }
- // Master marks the following operation on master node.
- func (d *SysGroupRoleDao) Master() *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Master()}
- }
- // Slave marks the following operation on slave node.
- // Note that it makes sense only if there's any slave node configured.
- func (d *SysGroupRoleDao) Slave() *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Slave()}
- }
- // Args sets custom arguments for model operation.
- func (d *SysGroupRoleDao) Args(args ...interface{}) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Args(args...)}
- }
- // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
- // The parameter <table> can be joined table and its joined condition,
- // and also with its alias name, like:
- // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
- // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
- func (d *SysGroupRoleDao) LeftJoin(table ...string) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.LeftJoin(table...)}
- }
- // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
- // The parameter <table> can be joined table and its joined condition,
- // and also with its alias name, like:
- // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
- // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
- func (d *SysGroupRoleDao) RightJoin(table ...string) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.RightJoin(table...)}
- }
- // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
- // The parameter <table> can be joined table and its joined condition,
- // and also with its alias name, like:
- // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
- // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
- func (d *SysGroupRoleDao) InnerJoin(table ...string) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.InnerJoin(table...)}
- }
- // Fields sets the operation fields of the model, multiple fields joined using char ','.
- // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
- func (d *SysGroupRoleDao) Fields(fieldNamesOrMapStruct ...interface{}) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
- }
- // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
- // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
- func (d *SysGroupRoleDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
- }
- // Option sets the extra operation option for the model.
- func (d *SysGroupRoleDao) Option(option int) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Option(option)}
- }
- // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
- // the data and where attributes for empty values.
- func (d *SysGroupRoleDao) OmitEmpty() *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.OmitEmpty()}
- }
- // Filter marks filtering the fields which does not exist in the fields of the operated table.
- func (d *SysGroupRoleDao) Filter() *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Filter()}
- }
- // Where sets the condition statement for the model. The parameter <where> can be type of
- // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
- // multiple conditions will be joined into where statement using "AND".
- // Eg:
- // Where("uid=10000")
- // Where("uid", 10000)
- // Where("money>? AND name like ?", 99999, "vip_%")
- // Where("uid", 1).Where("name", "john")
- // Where("status IN (?)", g.Slice{1,2,3})
- // Where("age IN(?,?)", 18, 50)
- // Where(User{ Id : 1, UserName : "john"})
- func (d *SysGroupRoleDao) Where(where interface{}, args ...interface{}) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Where(where, args...)}
- }
- // WherePri does the same logic as M.Where except that if the parameter <where>
- // is a single condition like int/string/float/slice, it treats the condition as the primary
- // key value. That is, if primary key is "id" and given <where> parameter as "123", the
- // WherePri function treats the condition as "id=123", but M.Where treats the condition
- // as string "123".
- func (d *SysGroupRoleDao) WherePri(where interface{}, args ...interface{}) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.WherePri(where, args...)}
- }
- // And adds "AND" condition to the where statement.
- func (d *SysGroupRoleDao) And(where interface{}, args ...interface{}) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.And(where, args...)}
- }
- // Or adds "OR" condition to the where statement.
- func (d *SysGroupRoleDao) Or(where interface{}, args ...interface{}) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Or(where, args...)}
- }
- // Group sets the "GROUP BY" statement for the model.
- func (d *SysGroupRoleDao) Group(groupBy string) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Group(groupBy)}
- }
- // Order sets the "ORDER BY" statement for the model.
- func (d *SysGroupRoleDao) Order(orderBy ...string) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Order(orderBy...)}
- }
- // Limit sets the "LIMIT" statement for the model.
- // The parameter <limit> can be either one or two number, if passed two number is passed,
- // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
- // statement.
- func (d *SysGroupRoleDao) Limit(limit ...int) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Limit(limit...)}
- }
- // Offset sets the "OFFSET" statement for the model.
- // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
- func (d *SysGroupRoleDao) Offset(offset int) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Offset(offset)}
- }
- // Page sets the paging number for the model.
- // The parameter <page> is started from 1 for paging.
- // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
- func (d *SysGroupRoleDao) Page(page, limit int) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Page(page, limit)}
- }
- // Batch sets the batch operation number for the model.
- func (d *SysGroupRoleDao) Batch(batch int) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Batch(batch)}
- }
- // Cache sets the cache feature for the model. It caches the result of the sql, which means
- // if there's another same sql request, it just reads and returns the result from cache, it
- // but not committed and executed into the database.
- //
- // If the parameter <duration> < 0, which means it clear the cache with given <name>.
- // If the parameter <duration> = 0, which means it never expires.
- // If the parameter <duration> > 0, which means it expires after <duration>.
- //
- // The optional parameter <name> is used to bind a name to the cache, which means you can later
- // control the cache like changing the <duration> or clearing the cache with specified <name>.
- //
- // Note that, the cache feature is disabled if the model is operating on a transaction.
- func (d *SysGroupRoleDao) Cache(duration time.Duration, name ...string) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Cache(duration, name...)}
- }
- // Data sets the operation data for the model.
- // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
- // Eg:
- // Data("uid=10000")
- // Data("uid", 10000)
- // Data(g.Map{"uid": 10000, "name":"john"})
- // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
- func (d *SysGroupRoleDao) Data(data ...interface{}) *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Data(data...)}
- }
- // All does "SELECT FROM ..." statement for the model.
- // It retrieves the records from table and returns the result as []*model.SysGroupRole.
- // It returns nil if there's no record retrieved with the given conditions from table.
- //
- // The optional parameter <where> is the same as the parameter of M.Where function,
- // see M.Where.
- func (d *SysGroupRoleDao) All(where ...interface{}) ([]*model.SysGroupRole, error) {
- all, err := d.M.All(where...)
- if err != nil {
- return nil, err
- }
- var entities []*model.SysGroupRole
- if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
- return nil, err
- }
- return entities, nil
- }
- // One retrieves one record from table and returns the result as *model.SysGroupRole.
- // It returns nil if there's no record retrieved with the given conditions from table.
- //
- // The optional parameter <where> is the same as the parameter of M.Where function,
- // see M.Where.
- func (d *SysGroupRoleDao) One(where ...interface{}) (*model.SysGroupRole, error) {
- one, err := d.M.One(where...)
- if err != nil {
- return nil, err
- }
- var entity *model.SysGroupRole
- if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
- return nil, err
- }
- return entity, nil
- }
- // FindOne retrieves and returns a single Record by M.WherePri and M.One.
- // Also see M.WherePri and M.One.
- func (d *SysGroupRoleDao) FindOne(where ...interface{}) (*model.SysGroupRole, error) {
- one, err := d.M.FindOne(where...)
- if err != nil {
- return nil, err
- }
- var entity *model.SysGroupRole
- if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
- return nil, err
- }
- return entity, nil
- }
- // FindAll retrieves and returns Result by by M.WherePri and M.All.
- // Also see M.WherePri and M.All.
- func (d *SysGroupRoleDao) FindAll(where ...interface{}) ([]*model.SysGroupRole, error) {
- all, err := d.M.FindAll(where...)
- if err != nil {
- return nil, err
- }
- var entities []*model.SysGroupRole
- if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
- return nil, err
- }
- return entities, nil
- }
- // Struct retrieves one record from table and converts it into given struct.
- // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
- // it can create the struct internally during converting.
- //
- // The optional parameter <where> is the same as the parameter of Model.Where function,
- // see Model.Where.
- //
- // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
- // from table and <pointer> is not nil.
- //
- // Eg:
- // user := new(User)
- // err := dao.User.Where("id", 1).Struct(user)
- //
- // user := (*User)(nil)
- // err := dao.User.Where("id", 1).Struct(&user)
- func (d *SysGroupRoleDao) Struct(pointer interface{}, where ...interface{}) error {
- return d.M.Struct(pointer, where...)
- }
- // Structs retrieves records from table and converts them into given struct slice.
- // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
- // slice internally during converting.
- //
- // The optional parameter <where> is the same as the parameter of Model.Where function,
- // see Model.Where.
- //
- // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
- // from table and <pointer> is not empty.
- //
- // Eg:
- // users := ([]User)(nil)
- // err := dao.User.Structs(&users)
- //
- // users := ([]*User)(nil)
- // err := dao.User.Structs(&users)
- func (d *SysGroupRoleDao) Structs(pointer interface{}, where ...interface{}) error {
- return d.M.Structs(pointer, where...)
- }
- // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
- // It calls function Struct if <pointer> is type of *struct/**struct.
- // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
- //
- // The optional parameter <where> is the same as the parameter of Model.Where function,
- // see Model.Where.
- //
- // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
- //
- // Eg:
- // user := new(User)
- // err := dao.User.Where("id", 1).Scan(user)
- //
- // user := (*User)(nil)
- // err := dao.User.Where("id", 1).Scan(&user)
- //
- // users := ([]User)(nil)
- // err := dao.User.Scan(&users)
- //
- // users := ([]*User)(nil)
- // err := dao.User.Scan(&users)
- func (d *SysGroupRoleDao) Scan(pointer interface{}, where ...interface{}) error {
- return d.M.Scan(pointer, where...)
- }
- // Chunk iterates the table with given size and callback function.
- func (d *SysGroupRoleDao) Chunk(limit int, callback func(entities []*model.SysGroupRole, err error) bool) {
- d.M.Chunk(limit, func(result gdb.Result, err error) bool {
- var entities []*model.SysGroupRole
- err = result.Structs(&entities)
- if err == sql.ErrNoRows {
- return false
- }
- return callback(entities, err)
- })
- }
- // LockUpdate sets the lock for update for current operation.
- func (d *SysGroupRoleDao) LockUpdate() *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.LockUpdate()}
- }
- // LockShared sets the lock in share mode for current operation.
- func (d *SysGroupRoleDao) LockShared() *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.LockShared()}
- }
- // Unscoped enables/disables the soft deleting feature.
- func (d *SysGroupRoleDao) Unscoped() *SysGroupRoleDao {
- return &SysGroupRoleDao{M: d.M.Unscoped()}
- }
|