2021-05-08 18:00:33 +08:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
|
|
import (
|
2021-07-28 18:03:19 +08:00
|
|
|
"mayfly-go/base/biz"
|
2021-05-08 18:00:33 +08:00
|
|
|
"mayfly-go/base/model"
|
2021-06-07 17:22:07 +08:00
|
|
|
"mayfly-go/server/devops/domain/entity"
|
|
|
|
|
"mayfly-go/server/devops/domain/repository"
|
2021-05-08 18:00:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type dbRepo struct{}
|
|
|
|
|
|
|
|
|
|
var DbDao repository.Db = &dbRepo{}
|
|
|
|
|
|
|
|
|
|
// 分页获取数据库信息列表
|
2021-07-28 18:03:19 +08:00
|
|
|
func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
2021-05-08 18:00:33 +08:00
|
|
|
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-11 14:04:09 +08:00
|
|
|
func (d *dbRepo) Count(condition *entity.Db) int64 {
|
|
|
|
|
return model.CountBy(condition)
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-08 18:00:33 +08:00
|
|
|
// 根据条件获取账号信息
|
|
|
|
|
func (d *dbRepo) GetDb(condition *entity.Db, cols ...string) error {
|
|
|
|
|
return model.GetBy(condition, cols...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据id获取
|
|
|
|
|
func (d *dbRepo) GetById(id uint64, cols ...string) *entity.Db {
|
|
|
|
|
db := new(entity.Db)
|
|
|
|
|
if err := model.GetById(db, id, cols...); err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return db
|
|
|
|
|
}
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
|
|
|
func (d *dbRepo) Insert(db *entity.Db) {
|
|
|
|
|
biz.ErrIsNil(model.Insert(db), "新增数据库信息失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *dbRepo) Update(db *entity.Db) {
|
|
|
|
|
biz.ErrIsNil(model.UpdateById(db), "更新数据库信息失败")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *dbRepo) Delete(id uint64) {
|
|
|
|
|
model.DeleteById(new(entity.Db), id)
|
|
|
|
|
}
|