mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 07:50:25 +08:00
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package persistence
|
|
|
|
import (
|
|
"mayfly-go/internal/db/domain/entity"
|
|
"mayfly-go/internal/db/domain/repository"
|
|
"mayfly-go/pkg/base"
|
|
"mayfly-go/pkg/gormx"
|
|
"mayfly-go/pkg/model"
|
|
)
|
|
|
|
type dbRepoImpl struct {
|
|
base.RepoImpl[*entity.Db]
|
|
}
|
|
|
|
func newDbRepo() repository.Db {
|
|
return &dbRepoImpl{base.RepoImpl[*entity.Db]{M: new(entity.Db)}}
|
|
}
|
|
|
|
// 分页获取数据库信息列表
|
|
func (d *dbRepoImpl) GetDbList(condition *entity.DbQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
|
qd := gormx.NewQueryWithTableName("t_db db").
|
|
Select("db.*, inst.name instance_name, inst.type instance_type, inst.host, inst.port, rac.username ").
|
|
Joins("JOIN t_db_instance inst ON db.instance_id = inst.id JOIN t_resource_auth_cert rac ON inst.code = rac.resource_code AND rac.resource_type = 2").
|
|
Eq("db.instance_id", condition.InstanceId).
|
|
Eq("db.id", condition.Id).
|
|
Like("db.database", condition.Database).
|
|
Eq("db.code", condition.Code).
|
|
In("db.code", condition.Codes).
|
|
Eq0("db."+model.DeletedColumn, model.ModelUndeleted).
|
|
Eq0("inst."+model.DeletedColumn, model.ModelUndeleted)
|
|
|
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
|
}
|
|
|
|
func (d *dbRepoImpl) Count(condition *entity.DbQuery) int64 {
|
|
where := make(map[string]any)
|
|
if len(condition.TagIds) > 0 {
|
|
where["tag_id"] = condition.TagIds
|
|
}
|
|
if condition.InstanceId > 0 {
|
|
where["instance_id"] = condition.InstanceId
|
|
}
|
|
if condition.Code != "" {
|
|
where["code"] = condition.Code
|
|
}
|
|
return d.CountByCond(where)
|
|
}
|