Files
mayfly-go/server/internal/mongo/infrastructure/persistence/mongo.go

32 lines
850 B
Go
Raw Normal View History

2022-05-17 20:23:08 +08:00
package persistence
import (
2022-09-09 18:26:08 +08:00
"mayfly-go/internal/mongo/domain/entity"
"mayfly-go/internal/mongo/domain/repository"
"mayfly-go/pkg/base"
"mayfly-go/pkg/model"
2022-05-17 20:23:08 +08:00
)
type mongoRepoImpl struct {
base.RepoImpl[*entity.Mongo]
}
2022-05-17 20:23:08 +08:00
2022-09-09 18:26:08 +08:00
func newMongoRepo() repository.Mongo {
return &mongoRepoImpl{base.RepoImpl[*entity.Mongo]{M: new(entity.Mongo)}}
2022-09-09 18:26:08 +08:00
}
2022-05-17 20:23:08 +08:00
// 分页获取数据库信息列表
func (d *mongoRepoImpl) GetList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
qd := model.NewCond().
Like("name", condition.Name).
2024-04-06 18:19:17 +08:00
Eq("code", condition.Code).
In("code", condition.Codes)
keyword := condition.Keyword
if keyword != "" {
keyword = "%" + keyword + "%"
qd.And("name like ? or code like ?", keyword, keyword)
}
2024-05-05 14:53:30 +08:00
return d.PageByCondToAny(qd, pageParam, toEntity)
2022-05-17 20:23:08 +08:00
}