mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-08 02:10:24 +08:00
29 lines
666 B
Go
29 lines
666 B
Go
package persistence
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"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) AddJobIfNotExists(_ context.Context, job *entity.DbBinlog) error {
|
|
if err := global.Db.Clauses(clause.OnConflict{DoNothing: true}).Create(job).Error; err != nil {
|
|
return fmt.Errorf("启动 binlog 下载失败: %w", err)
|
|
}
|
|
return nil
|
|
}
|