123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- package model
- import (
- "context"
- "gorm.io/gorm"
- "gorm.io/gorm/clause"
- "gorm.io/gorm/schema"
- "gorm.io/gen"
- "gorm.io/gen/field"
- "gorm.io/plugin/dbresolver"
- "icloudapp.cn/tools/service/entity"
- )
- func newRole(db *gorm.DB, opts ...gen.DOOption) MRole {
- _MRole := MRole{}
- _MRole.MRoleDo.UseDB(db, opts...)
- _MRole.MRoleDo.UseModel(&entity.Role{})
- tableName := _MRole.MRoleDo.TableName()
- _MRole.ALL = field.NewAsterisk(tableName)
- _MRole.RoleID = field.NewInt64(tableName, "role_id")
- _MRole.RoleName = field.NewString(tableName, "role_name")
- _MRole.ModelIds = field.NewString(tableName, "model_ids")
- _MRole.RoleStatus = field.NewInt64(tableName, "role_status")
- _MRole.OperatorUID = field.NewInt64(tableName, "operator_uid")
- _MRole.CreateAt = field.NewTime(tableName, "create_at")
- _MRole.UpdateAt = field.NewTime(tableName, "update_at")
- _MRole.fillFieldMap()
- return _MRole
- }
- type MRole struct {
- MRoleDo MRoleDo
- ALL field.Asterisk
- RoleID field.Int64
- RoleName field.String
- ModelIds field.String
- RoleStatus field.Int64
- OperatorUID field.Int64
- CreateAt field.Time
- UpdateAt field.Time
- fieldMap map[string]field.Expr
- }
- func (r MRole) Table(newTableName string) *MRole {
- r.MRoleDo.UseTable(newTableName)
- return r.updateTableName(newTableName)
- }
- func (r MRole) As(alias string) *MRole {
- r.MRoleDo.DO = *(r.MRoleDo.As(alias).(*gen.DO))
- return r.updateTableName(alias)
- }
- func (r *MRole) updateTableName(table string) *MRole {
- r.ALL = field.NewAsterisk(table)
- r.RoleID = field.NewInt64(table, "role_id")
- r.RoleName = field.NewString(table, "role_name")
- r.ModelIds = field.NewString(table, "model_ids")
- r.RoleStatus = field.NewInt64(table, "role_status")
- r.OperatorUID = field.NewInt64(table, "operator_uid")
- r.CreateAt = field.NewTime(table, "create_at")
- r.UpdateAt = field.NewTime(table, "update_at")
- r.fillFieldMap()
- return r
- }
- func (r *MRole) WithContext(ctx context.Context) IRoleDo { return r.MRoleDo.WithContext(ctx) }
- func (r MRole) TableName() string { return r.MRoleDo.TableName() }
- func (r MRole) Alias() string { return r.MRoleDo.Alias() }
- func (r *MRole) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
- _f, ok := r.fieldMap[fieldName]
- if !ok || _f == nil {
- return nil, false
- }
- _oe, ok := _f.(field.OrderExpr)
- return _oe, ok
- }
- func (r *MRole) fillFieldMap() {
- r.fieldMap = make(map[string]field.Expr, 7)
- r.fieldMap["role_id"] = r.RoleID
- r.fieldMap["role_name"] = r.RoleName
- r.fieldMap["model_ids"] = r.ModelIds
- r.fieldMap["role_status"] = r.RoleStatus
- r.fieldMap["operator_uid"] = r.OperatorUID
- r.fieldMap["create_at"] = r.CreateAt
- r.fieldMap["update_at"] = r.UpdateAt
- }
- func (r MRole) clone(db *gorm.DB) MRole {
- r.MRoleDo.ReplaceConnPool(db.Statement.ConnPool)
- return r
- }
- func (r MRole) replaceDB(db *gorm.DB) MRole {
- r.MRoleDo.ReplaceDB(db)
- return r
- }
- type MRoleDo struct{ gen.DO }
- type IRoleDo interface {
- gen.SubQuery
- Debug() IRoleDo
- WithContext(ctx context.Context) IRoleDo
- WithResult(fc func(tx gen.Dao)) gen.ResultInfo
- ReplaceDB(db *gorm.DB)
- ReadDB() IRoleDo
- WriteDB() IRoleDo
- As(alias string) gen.Dao
- Session(config *gorm.Session) IRoleDo
- Columns(cols ...field.Expr) gen.Columns
- Clauses(conds ...clause.Expression) IRoleDo
- Not(conds ...gen.Condition) IRoleDo
- Or(conds ...gen.Condition) IRoleDo
- Select(conds ...field.Expr) IRoleDo
- Where(conds ...gen.Condition) IRoleDo
- Order(conds ...field.Expr) IRoleDo
- Distinct(cols ...field.Expr) IRoleDo
- Omit(cols ...field.Expr) IRoleDo
- Join(table schema.Tabler, on ...field.Expr) IRoleDo
- LeftJoin(table schema.Tabler, on ...field.Expr) IRoleDo
- RightJoin(table schema.Tabler, on ...field.Expr) IRoleDo
- Group(cols ...field.Expr) IRoleDo
- Having(conds ...gen.Condition) IRoleDo
- Limit(limit int) IRoleDo
- Offset(offset int) IRoleDo
- Count() (count int64, err error)
- Scopes(funcs ...func(gen.Dao) gen.Dao) IRoleDo
- Unscoped() IRoleDo
- Create(values ...*entity.Role) error
- CreateInBatches(values []*entity.Role, batchSize int) error
- Save(values ...*entity.Role) error
- First() (*entity.Role, error)
- Take() (*entity.Role, error)
- Last() (*entity.Role, error)
- Find() ([]*entity.Role, error)
- FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Role, err error)
- FindInBatches(result *[]*entity.Role, batchSize int, fc func(tx gen.Dao, batch int) error) error
- Pluck(column field.Expr, dest interface{}) error
- Delete(...*entity.Role) (info gen.ResultInfo, err error)
- Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
- UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
- Updates(value interface{}) (info gen.ResultInfo, err error)
- UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
- UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
- UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
- UpdateFrom(q gen.SubQuery) gen.Dao
- Attrs(attrs ...field.AssignExpr) IRoleDo
- Assign(attrs ...field.AssignExpr) IRoleDo
- Joins(fields ...field.RelationField) IRoleDo
- Preload(fields ...field.RelationField) IRoleDo
- FirstOrInit() (*entity.Role, error)
- FirstOrCreate() (*entity.Role, error)
- FindByPage(offset int, limit int) (result []*entity.Role, count int64, err error)
- ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
- Scan(result interface{}) (err error)
- Returning(value interface{}, columns ...string) IRoleDo
- UnderlyingDB() *gorm.DB
- schema.Tabler
- }
- func (r MRoleDo) Debug() IRoleDo {
- return r.withDO(r.DO.Debug())
- }
- func (r MRoleDo) WithContext(ctx context.Context) IRoleDo {
- return r.withDO(r.DO.WithContext(ctx))
- }
- func (r MRoleDo) ReadDB() IRoleDo {
- return r.Clauses(dbresolver.Read)
- }
- func (r MRoleDo) WriteDB() IRoleDo {
- return r.Clauses(dbresolver.Write)
- }
- func (r MRoleDo) Session(config *gorm.Session) IRoleDo {
- return r.withDO(r.DO.Session(config))
- }
- func (r MRoleDo) Clauses(conds ...clause.Expression) IRoleDo {
- return r.withDO(r.DO.Clauses(conds...))
- }
- func (r MRoleDo) Returning(value interface{}, columns ...string) IRoleDo {
- return r.withDO(r.DO.Returning(value, columns...))
- }
- func (r MRoleDo) Not(conds ...gen.Condition) IRoleDo {
- return r.withDO(r.DO.Not(conds...))
- }
- func (r MRoleDo) Or(conds ...gen.Condition) IRoleDo {
- return r.withDO(r.DO.Or(conds...))
- }
- func (r MRoleDo) Select(conds ...field.Expr) IRoleDo {
- return r.withDO(r.DO.Select(conds...))
- }
- func (r MRoleDo) Where(conds ...gen.Condition) IRoleDo {
- return r.withDO(r.DO.Where(conds...))
- }
- func (r MRoleDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) IRoleDo {
- return r.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
- }
- func (r MRoleDo) Order(conds ...field.Expr) IRoleDo {
- return r.withDO(r.DO.Order(conds...))
- }
- func (r MRoleDo) Distinct(cols ...field.Expr) IRoleDo {
- return r.withDO(r.DO.Distinct(cols...))
- }
- func (r MRoleDo) Omit(cols ...field.Expr) IRoleDo {
- return r.withDO(r.DO.Omit(cols...))
- }
- func (r MRoleDo) Join(table schema.Tabler, on ...field.Expr) IRoleDo {
- return r.withDO(r.DO.Join(table, on...))
- }
- func (r MRoleDo) LeftJoin(table schema.Tabler, on ...field.Expr) IRoleDo {
- return r.withDO(r.DO.LeftJoin(table, on...))
- }
- func (r MRoleDo) RightJoin(table schema.Tabler, on ...field.Expr) IRoleDo {
- return r.withDO(r.DO.RightJoin(table, on...))
- }
- func (r MRoleDo) Group(cols ...field.Expr) IRoleDo {
- return r.withDO(r.DO.Group(cols...))
- }
- func (r MRoleDo) Having(conds ...gen.Condition) IRoleDo {
- return r.withDO(r.DO.Having(conds...))
- }
- func (r MRoleDo) Limit(limit int) IRoleDo {
- return r.withDO(r.DO.Limit(limit))
- }
- func (r MRoleDo) Offset(offset int) IRoleDo {
- return r.withDO(r.DO.Offset(offset))
- }
- func (r MRoleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IRoleDo {
- return r.withDO(r.DO.Scopes(funcs...))
- }
- func (r MRoleDo) Unscoped() IRoleDo {
- return r.withDO(r.DO.Unscoped())
- }
- func (r MRoleDo) Create(values ...*entity.Role) error {
- if len(values) == 0 {
- return nil
- }
- return r.DO.Create(values)
- }
- func (r MRoleDo) CreateInBatches(values []*entity.Role, batchSize int) error {
- return r.DO.CreateInBatches(values, batchSize)
- }
- func (r MRoleDo) Save(values ...*entity.Role) error {
- if len(values) == 0 {
- return nil
- }
- return r.DO.Save(values)
- }
- func (r MRoleDo) First() (*entity.Role, error) {
- if result, err := r.DO.First(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Role), nil
- }
- }
- func (r MRoleDo) Take() (*entity.Role, error) {
- if result, err := r.DO.Take(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Role), nil
- }
- }
- func (r MRoleDo) Last() (*entity.Role, error) {
- if result, err := r.DO.Last(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Role), nil
- }
- }
- func (r MRoleDo) Find() ([]*entity.Role, error) {
- result, err := r.DO.Find()
- return result.([]*entity.Role), err
- }
- func (r MRoleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Role, err error) {
- buf := make([]*entity.Role, 0, batchSize)
- err = r.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
- defer func() { results = append(results, buf...) }()
- return fc(tx, batch)
- })
- return results, err
- }
- func (r MRoleDo) FindInBatches(result *[]*entity.Role, batchSize int, fc func(tx gen.Dao, batch int) error) error {
- return r.DO.FindInBatches(result, batchSize, fc)
- }
- func (r MRoleDo) Attrs(attrs ...field.AssignExpr) IRoleDo {
- return r.withDO(r.DO.Attrs(attrs...))
- }
- func (r MRoleDo) Assign(attrs ...field.AssignExpr) IRoleDo {
- return r.withDO(r.DO.Assign(attrs...))
- }
- func (r MRoleDo) Joins(fields ...field.RelationField) IRoleDo {
- for _, _f := range fields {
- r = *r.withDO(r.DO.Joins(_f))
- }
- return &r
- }
- func (r MRoleDo) Preload(fields ...field.RelationField) IRoleDo {
- for _, _f := range fields {
- r = *r.withDO(r.DO.Preload(_f))
- }
- return &r
- }
- func (r MRoleDo) FirstOrInit() (*entity.Role, error) {
- if result, err := r.DO.FirstOrInit(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Role), nil
- }
- }
- func (r MRoleDo) FirstOrCreate() (*entity.Role, error) {
- if result, err := r.DO.FirstOrCreate(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Role), nil
- }
- }
- func (r MRoleDo) FindByPage(offset int, limit int) (result []*entity.Role, count int64, err error) {
- result, err = r.Offset(offset).Limit(limit).Find()
- if err != nil {
- return
- }
- if size := len(result); 0 < limit && 0 < size && size < limit {
- count = int64(size + offset)
- return
- }
- count, err = r.Offset(-1).Limit(-1).Count()
- return
- }
- func (r MRoleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
- count, err = r.Count()
- if err != nil {
- return
- }
- err = r.Offset(offset).Limit(limit).Scan(result)
- return
- }
- func (r MRoleDo) Scan(result interface{}) (err error) {
- return r.DO.Scan(result)
- }
- func (r MRoleDo) Delete(models ...*entity.Role) (result gen.ResultInfo, err error) {
- return r.DO.Delete(models)
- }
- func (r *MRoleDo) withDO(do gen.Dao) *MRoleDo {
- r.DO = *do.(*gen.DO)
- return r
- }
|