123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- 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 newModule(db *gorm.DB, opts ...gen.DOOption) MModule {
- _MModule := MModule{}
- _MModule.MModuleDo.UseDB(db, opts...)
- _MModule.MModuleDo.UseModel(&entity.Module{})
- tableName := _MModule.MModuleDo.TableName()
- _MModule.ALL = field.NewAsterisk(tableName)
- _MModule.ModelID = field.NewInt64(tableName, "model_id")
- _MModule.ModelName = field.NewString(tableName, "model_name")
- _MModule.ModelGroup = field.NewString(tableName, "model_group")
- _MModule.Menu = field.NewString(tableName, "menu")
- _MModule.ModelURL = field.NewString(tableName, "model_url")
- _MModule.ModelIndex = field.NewInt64(tableName, "model_index")
- _MModule.Visible = field.NewInt64(tableName, "visible")
- _MModule.ModelStatus = field.NewInt64(tableName, "model_status")
- _MModule.OperatorUID = field.NewInt64(tableName, "operator_uid")
- _MModule.CreateAt = field.NewTime(tableName, "create_at")
- _MModule.UpdateAt = field.NewTime(tableName, "update_at")
- _MModule.fillFieldMap()
- return _MModule
- }
- type MModule struct {
- MModuleDo MModuleDo
- ALL field.Asterisk
- ModelID field.Int64
- ModelName field.String
- ModelGroup field.String
- Menu field.String
- ModelURL field.String
- ModelIndex field.Int64
- Visible field.Int64
- ModelStatus field.Int64
- OperatorUID field.Int64
- CreateAt field.Time
- UpdateAt field.Time
- fieldMap map[string]field.Expr
- }
- func (m MModule) Table(newTableName string) *MModule {
- m.MModuleDo.UseTable(newTableName)
- return m.updateTableName(newTableName)
- }
- func (m MModule) As(alias string) *MModule {
- m.MModuleDo.DO = *(m.MModuleDo.As(alias).(*gen.DO))
- return m.updateTableName(alias)
- }
- func (m *MModule) updateTableName(table string) *MModule {
- m.ALL = field.NewAsterisk(table)
- m.ModelID = field.NewInt64(table, "model_id")
- m.ModelName = field.NewString(table, "model_name")
- m.ModelGroup = field.NewString(table, "model_group")
- m.Menu = field.NewString(table, "menu")
- m.ModelURL = field.NewString(table, "model_url")
- m.ModelIndex = field.NewInt64(table, "model_index")
- m.Visible = field.NewInt64(table, "visible")
- m.ModelStatus = field.NewInt64(table, "model_status")
- m.OperatorUID = field.NewInt64(table, "operator_uid")
- m.CreateAt = field.NewTime(table, "create_at")
- m.UpdateAt = field.NewTime(table, "update_at")
- m.fillFieldMap()
- return m
- }
- func (m *MModule) WithContext(ctx context.Context) IModuleDo { return m.MModuleDo.WithContext(ctx) }
- func (m MModule) TableName() string { return m.MModuleDo.TableName() }
- func (m MModule) Alias() string { return m.MModuleDo.Alias() }
- func (m *MModule) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
- _f, ok := m.fieldMap[fieldName]
- if !ok || _f == nil {
- return nil, false
- }
- _oe, ok := _f.(field.OrderExpr)
- return _oe, ok
- }
- func (m *MModule) fillFieldMap() {
- m.fieldMap = make(map[string]field.Expr, 11)
- m.fieldMap["model_id"] = m.ModelID
- m.fieldMap["model_name"] = m.ModelName
- m.fieldMap["model_group"] = m.ModelGroup
- m.fieldMap["menu"] = m.Menu
- m.fieldMap["model_url"] = m.ModelURL
- m.fieldMap["model_index"] = m.ModelIndex
- m.fieldMap["visible"] = m.Visible
- m.fieldMap["model_status"] = m.ModelStatus
- m.fieldMap["operator_uid"] = m.OperatorUID
- m.fieldMap["create_at"] = m.CreateAt
- m.fieldMap["update_at"] = m.UpdateAt
- }
- func (m MModule) clone(db *gorm.DB) MModule {
- m.MModuleDo.ReplaceConnPool(db.Statement.ConnPool)
- return m
- }
- func (m MModule) replaceDB(db *gorm.DB) MModule {
- m.MModuleDo.ReplaceDB(db)
- return m
- }
- type MModuleDo struct{ gen.DO }
- type IModuleDo interface {
- gen.SubQuery
- Debug() IModuleDo
- WithContext(ctx context.Context) IModuleDo
- WithResult(fc func(tx gen.Dao)) gen.ResultInfo
- ReplaceDB(db *gorm.DB)
- ReadDB() IModuleDo
- WriteDB() IModuleDo
- As(alias string) gen.Dao
- Session(config *gorm.Session) IModuleDo
- Columns(cols ...field.Expr) gen.Columns
- Clauses(conds ...clause.Expression) IModuleDo
- Not(conds ...gen.Condition) IModuleDo
- Or(conds ...gen.Condition) IModuleDo
- Select(conds ...field.Expr) IModuleDo
- Where(conds ...gen.Condition) IModuleDo
- Order(conds ...field.Expr) IModuleDo
- Distinct(cols ...field.Expr) IModuleDo
- Omit(cols ...field.Expr) IModuleDo
- Join(table schema.Tabler, on ...field.Expr) IModuleDo
- LeftJoin(table schema.Tabler, on ...field.Expr) IModuleDo
- RightJoin(table schema.Tabler, on ...field.Expr) IModuleDo
- Group(cols ...field.Expr) IModuleDo
- Having(conds ...gen.Condition) IModuleDo
- Limit(limit int) IModuleDo
- Offset(offset int) IModuleDo
- Count() (count int64, err error)
- Scopes(funcs ...func(gen.Dao) gen.Dao) IModuleDo
- Unscoped() IModuleDo
- Create(values ...*entity.Module) error
- CreateInBatches(values []*entity.Module, batchSize int) error
- Save(values ...*entity.Module) error
- First() (*entity.Module, error)
- Take() (*entity.Module, error)
- Last() (*entity.Module, error)
- Find() ([]*entity.Module, error)
- FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Module, err error)
- FindInBatches(result *[]*entity.Module, batchSize int, fc func(tx gen.Dao, batch int) error) error
- Pluck(column field.Expr, dest interface{}) error
- Delete(...*entity.Module) (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) IModuleDo
- Assign(attrs ...field.AssignExpr) IModuleDo
- Joins(fields ...field.RelationField) IModuleDo
- Preload(fields ...field.RelationField) IModuleDo
- FirstOrInit() (*entity.Module, error)
- FirstOrCreate() (*entity.Module, error)
- FindByPage(offset int, limit int) (result []*entity.Module, 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) IModuleDo
- UnderlyingDB() *gorm.DB
- schema.Tabler
- }
- func (m MModuleDo) Debug() IModuleDo {
- return m.withDO(m.DO.Debug())
- }
- func (m MModuleDo) WithContext(ctx context.Context) IModuleDo {
- return m.withDO(m.DO.WithContext(ctx))
- }
- func (m MModuleDo) ReadDB() IModuleDo {
- return m.Clauses(dbresolver.Read)
- }
- func (m MModuleDo) WriteDB() IModuleDo {
- return m.Clauses(dbresolver.Write)
- }
- func (m MModuleDo) Session(config *gorm.Session) IModuleDo {
- return m.withDO(m.DO.Session(config))
- }
- func (m MModuleDo) Clauses(conds ...clause.Expression) IModuleDo {
- return m.withDO(m.DO.Clauses(conds...))
- }
- func (m MModuleDo) Returning(value interface{}, columns ...string) IModuleDo {
- return m.withDO(m.DO.Returning(value, columns...))
- }
- func (m MModuleDo) Not(conds ...gen.Condition) IModuleDo {
- return m.withDO(m.DO.Not(conds...))
- }
- func (m MModuleDo) Or(conds ...gen.Condition) IModuleDo {
- return m.withDO(m.DO.Or(conds...))
- }
- func (m MModuleDo) Select(conds ...field.Expr) IModuleDo {
- return m.withDO(m.DO.Select(conds...))
- }
- func (m MModuleDo) Where(conds ...gen.Condition) IModuleDo {
- return m.withDO(m.DO.Where(conds...))
- }
- func (m MModuleDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) IModuleDo {
- return m.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
- }
- func (m MModuleDo) Order(conds ...field.Expr) IModuleDo {
- return m.withDO(m.DO.Order(conds...))
- }
- func (m MModuleDo) Distinct(cols ...field.Expr) IModuleDo {
- return m.withDO(m.DO.Distinct(cols...))
- }
- func (m MModuleDo) Omit(cols ...field.Expr) IModuleDo {
- return m.withDO(m.DO.Omit(cols...))
- }
- func (m MModuleDo) Join(table schema.Tabler, on ...field.Expr) IModuleDo {
- return m.withDO(m.DO.Join(table, on...))
- }
- func (m MModuleDo) LeftJoin(table schema.Tabler, on ...field.Expr) IModuleDo {
- return m.withDO(m.DO.LeftJoin(table, on...))
- }
- func (m MModuleDo) RightJoin(table schema.Tabler, on ...field.Expr) IModuleDo {
- return m.withDO(m.DO.RightJoin(table, on...))
- }
- func (m MModuleDo) Group(cols ...field.Expr) IModuleDo {
- return m.withDO(m.DO.Group(cols...))
- }
- func (m MModuleDo) Having(conds ...gen.Condition) IModuleDo {
- return m.withDO(m.DO.Having(conds...))
- }
- func (m MModuleDo) Limit(limit int) IModuleDo {
- return m.withDO(m.DO.Limit(limit))
- }
- func (m MModuleDo) Offset(offset int) IModuleDo {
- return m.withDO(m.DO.Offset(offset))
- }
- func (m MModuleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IModuleDo {
- return m.withDO(m.DO.Scopes(funcs...))
- }
- func (m MModuleDo) Unscoped() IModuleDo {
- return m.withDO(m.DO.Unscoped())
- }
- func (m MModuleDo) Create(values ...*entity.Module) error {
- if len(values) == 0 {
- return nil
- }
- return m.DO.Create(values)
- }
- func (m MModuleDo) CreateInBatches(values []*entity.Module, batchSize int) error {
- return m.DO.CreateInBatches(values, batchSize)
- }
- func (m MModuleDo) Save(values ...*entity.Module) error {
- if len(values) == 0 {
- return nil
- }
- return m.DO.Save(values)
- }
- func (m MModuleDo) First() (*entity.Module, error) {
- if result, err := m.DO.First(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Module), nil
- }
- }
- func (m MModuleDo) Take() (*entity.Module, error) {
- if result, err := m.DO.Take(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Module), nil
- }
- }
- func (m MModuleDo) Last() (*entity.Module, error) {
- if result, err := m.DO.Last(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Module), nil
- }
- }
- func (m MModuleDo) Find() ([]*entity.Module, error) {
- result, err := m.DO.Find()
- return result.([]*entity.Module), err
- }
- func (m MModuleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Module, err error) {
- buf := make([]*entity.Module, 0, batchSize)
- err = m.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 (m MModuleDo) FindInBatches(result *[]*entity.Module, batchSize int, fc func(tx gen.Dao, batch int) error) error {
- return m.DO.FindInBatches(result, batchSize, fc)
- }
- func (m MModuleDo) Attrs(attrs ...field.AssignExpr) IModuleDo {
- return m.withDO(m.DO.Attrs(attrs...))
- }
- func (m MModuleDo) Assign(attrs ...field.AssignExpr) IModuleDo {
- return m.withDO(m.DO.Assign(attrs...))
- }
- func (m MModuleDo) Joins(fields ...field.RelationField) IModuleDo {
- for _, _f := range fields {
- m = *m.withDO(m.DO.Joins(_f))
- }
- return &m
- }
- func (m MModuleDo) Preload(fields ...field.RelationField) IModuleDo {
- for _, _f := range fields {
- m = *m.withDO(m.DO.Preload(_f))
- }
- return &m
- }
- func (m MModuleDo) FirstOrInit() (*entity.Module, error) {
- if result, err := m.DO.FirstOrInit(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Module), nil
- }
- }
- func (m MModuleDo) FirstOrCreate() (*entity.Module, error) {
- if result, err := m.DO.FirstOrCreate(); err != nil {
- return nil, err
- } else {
- return result.(*entity.Module), nil
- }
- }
- func (m MModuleDo) FindByPage(offset int, limit int) (result []*entity.Module, count int64, err error) {
- result, err = m.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 = m.Offset(-1).Limit(-1).Count()
- return
- }
- func (m MModuleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
- count, err = m.Count()
- if err != nil {
- return
- }
- err = m.Offset(offset).Limit(limit).Scan(result)
- return
- }
- func (m MModuleDo) Scan(result interface{}) (err error) {
- return m.DO.Scan(result)
- }
- func (m MModuleDo) Delete(models ...*entity.Module) (result gen.ResultInfo, err error) {
- return m.DO.Delete(models)
- }
- func (m *MModuleDo) withDO(do gen.Dao) *MModuleDo {
- m.DO = *do.(*gen.DO)
- return m
- }
|