go_dreamfactory/modules/library/model_hunting.go
2022-09-07 20:07:56 +08:00

45 lines
1.1 KiB
Go

package library
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelLibrary struct {
modules.MCompModel
module *Library
}
func (this *modelLibrary) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableLibrary)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Library)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *modelLibrary) modifyLibraryDataByObjId(uid string, data map[string]interface{}) error {
return this.Change(uid, data)
}
// 获取列表信息
func (this *modelLibrary) getLibraryList(uid string) (result *pb.DBHero, err error) {
result = &pb.DBHero{}
if err = this.Get(uid, result); err != nil && mgo.MongodbNil != err {
return
}
err = nil
return result, err
}