Files
mayfly-go/server/internal/db/infrastructure/persistence/db_binlog.go

29 lines
669 B
Go
Raw Normal View History

2023-12-27 22:59:20 +08:00
package persistence
import (
"context"
"fmt"
2023-12-27 22:59:20 +08:00
"gorm.io/gorm/clause"
"mayfly-go/internal/db/domain/entity"
"mayfly-go/internal/db/domain/repository"
"mayfly-go/pkg/base"
"mayfly-go/pkg/global"
)
var _ repository.DbBinlog = (*dbBinlogRepoImpl)(nil)
type dbBinlogRepoImpl struct {
base.RepoImpl[*entity.DbBinlog]
}
func NewDbBinlogRepo() repository.DbBinlog {
return &dbBinlogRepoImpl{}
}
func (d *dbBinlogRepoImpl) AddTaskIfNotExists(_ context.Context, task *entity.DbBinlog) error {
if err := global.Db.Clauses(clause.OnConflict{DoNothing: true}).Create(task).Error; err != nil {
return fmt.Errorf("启动 binlog 下载失败: %w", err)
2023-12-27 22:59:20 +08:00
}
return nil
2023-12-27 22:59:20 +08:00
}