Help us shape the future of Go! Take the 2026 Go Developer Survey

dao

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeLikePattern

func EscapeLikePattern(s string) string

EscapeLikePattern 转义 SQL LIKE 模式中的通配符(% 和 _), 防止用户搜索词被当作通配符使用导致意外宽匹配。

func FindByID

func FindByID[T any](db *gorm.DB, id uint) (*T, error)

FindByID 根据 ID 查找记录

func FindByKey

func FindByKey[T any](db *gorm.DB, key string) (*T, error)

FindByKey 根据 key 字段查找记录

func Paginate

func Paginate[T any](db *gorm.DB, page Pagination, dest *[]*T) (int64, error)

Paginate 执行分页查询

Types

type MirrorChannelDAO

type MirrorChannelDAO struct {
	// contains filtered or unexported fields
}

MirrorChannelDAO 镜像通道与目标。

func NewMirrorChannelDAO

func NewMirrorChannelDAO(db *gorm.DB) *MirrorChannelDAO

func (*MirrorChannelDAO) Create

func (d *MirrorChannelDAO) Create(ch *model.MirrorChannel) error

func (*MirrorChannelDAO) CreateTarget

func (d *MirrorChannelDAO) CreateTarget(t *model.MirrorTarget) error

func (*MirrorChannelDAO) Delete

func (d *MirrorChannelDAO) Delete(id uint) error

Delete 软删通道及其目标。

func (*MirrorChannelDAO) DeleteTarget

func (d *MirrorChannelDAO) DeleteTarget(id uint) error

func (*MirrorChannelDAO) FindAll

func (d *MirrorChannelDAO) FindAll(page Pagination) ([]*model.MirrorChannel, int64, error)

func (*MirrorChannelDAO) FindByID

func (d *MirrorChannelDAO) FindByID(id uint) (*model.MirrorChannel, error)

func (*MirrorChannelDAO) FindTargetByID

func (d *MirrorChannelDAO) FindTargetByID(id uint) (*model.MirrorTarget, error)

func (*MirrorChannelDAO) FindTargets

func (d *MirrorChannelDAO) FindTargets(channelID uint) ([]*model.MirrorTarget, error)

func (*MirrorChannelDAO) Update

func (d *MirrorChannelDAO) Update(ch *model.MirrorChannel) error

func (*MirrorChannelDAO) UpdateTarget

func (d *MirrorChannelDAO) UpdateTarget(t *model.MirrorTarget) error

type MirrorRunDAO

type MirrorRunDAO struct {
	// contains filtered or unexported fields
}

MirrorRunDAO 镜像执行记录。

func NewMirrorRunDAO

func NewMirrorRunDAO(db *gorm.DB) *MirrorRunDAO

func (*MirrorRunDAO) Create

func (d *MirrorRunDAO) Create(run *model.MirrorRun) error

func (*MirrorRunDAO) FindAllByChannel

func (d *MirrorRunDAO) FindAllByChannel(channelID uint) ([]*model.MirrorRun, error)

FindAllByChannel 不分页拉全量(版本矩阵合并用;单通道记录量可控)。

func (*MirrorRunDAO) FindByChannel

func (d *MirrorRunDAO) FindByChannel(channelID uint, page Pagination) ([]*model.MirrorRun, int64, error)

func (*MirrorRunDAO) FindByChannelAndTargetAndTags

func (d *MirrorRunDAO) FindByChannelAndTargetAndTags(channelID, targetID uint, tag string) ([]*model.MirrorRun, error)

FindByChannelAndTargetAndTags 精确定位某个 tag 最近一次执行(矩阵合并)。 tags 是逗号分隔列表;用边界匹配替代旧的 %tag% 模糊匹配—— 否则 tag "v1" 会误匹配 "v10"、"revert-v1" 等不相关记录。

func (*MirrorRunDAO) FindByID

func (d *MirrorRunDAO) FindByID(id uint) (*model.MirrorRun, error)

func (*MirrorRunDAO) HasRunningByChannel

func (d *MirrorRunDAO) HasRunningByChannel(channelID uint) (bool, error)

HasRunningByChannel 是否存在进行中的执行(同通道互斥)。

func (*MirrorRunDAO) Update

func (d *MirrorRunDAO) Update(run *model.MirrorRun) error

type OperationLogDAO

type OperationLogDAO struct {
	// contains filtered or unexported fields
}

func NewOperationLogDAO

func NewOperationLogDAO(db *gorm.DB) *OperationLogDAO

func (*OperationLogDAO) CountAll

func (d *OperationLogDAO) CountAll() (int64, error)

CountAll 统计全部审计日志数。

func (*OperationLogDAO) CountSince

func (d *OperationLogDAO) CountSince(t time.Time) (int64, error)

CountSince 统计 created_at >= t 的记录数。

func (*OperationLogDAO) Create

func (d *OperationLogDAO) Create(log *model.OperationLog) error

Create 写入一条审计日志。

func (*OperationLogDAO) Latest added in v0.6.0

func (d *OperationLogDAO) Latest() (*model.OperationLog, error)

Latest 返回最新一条审计(用于哈希链续接);无记录时返回 nil,nil。

func (*OperationLogDAO) List

List 按过滤条件分页查询审计日志,返回列表与总数。

func (*OperationLogDAO) ListAscending added in v0.6.0

func (d *OperationLogDAO) ListAscending() ([]*model.OperationLog, error)

ListAscending 按 id 升序返回全部审计(哈希链校验用)。

func (*OperationLogDAO) StatsOnce

func (d *OperationLogDAO) StatsOnce(startOfToday time.Time) (*StatsResult, error)

StatsOnce 一次查询返回今日、近 7 天、总操作数(替代三次串行 COUNT)。

type OperationLogFilter

type OperationLogFilter struct {
	Search    string // LIKE resource / detail
	Action    string // 精确匹配
	Actor     string // 精确匹配
	StartDate string // YYYY-MM-DD(含,按 created_at 起算)
	EndDate   string // YYYY-MM-DD(含,按 created_at 止算)
}

OperationLogFilter 审计日志过滤条件。

type Pagination

type Pagination struct {
	Offset int
	Limit  int
}

func DefaultPagination

func DefaultPagination(offset, limit int) Pagination

type PlatformDAO

type PlatformDAO struct {
	// contains filtered or unexported fields
}

PlatformDAO 平台数据访问对象。 AccessToken 与 repo_dao 一致采用加密存储:写入加密、读取解密; 读取解密失败视为存量明文,原样返回(下次写入时自动转为密文)。

func NewPlatformDAO

func NewPlatformDAO(db *gorm.DB) (*PlatformDAO, error)

NewPlatformDAO 创建 PlatformDAO

func (*PlatformDAO) Count

func (d *PlatformDAO) Count() (int64, error)

Count 统计平台数量

func (*PlatformDAO) Create

func (d *PlatformDAO) Create(platform *model.Platform) error

Create 创建平台

func (*PlatformDAO) Delete

func (d *PlatformDAO) Delete(key string) error

Delete 删除平台(软删除)

func (*PlatformDAO) FindAll

func (d *PlatformDAO) FindAll() ([]*model.Platform, error)

FindAll 查找所有平台

func (*PlatformDAO) FindByID

func (d *PlatformDAO) FindByID(id uint) (*model.Platform, error)

FindByID 根据 ID 查找平台(not found 返回 nil,nil,与 RepoDAO 行为一致)。

func (*PlatformDAO) FindByKey

func (d *PlatformDAO) FindByKey(key string) (*model.Platform, error)

FindByKey 根据 Key 查找平台(not found 返回 nil,nil,与 RepoDAO 行为一致)。

func (*PlatformDAO) FindByType

func (d *PlatformDAO) FindByType(platformType string) ([]*model.Platform, error)

FindByType 根据类型查找平台

func (*PlatformDAO) FindDefault

func (d *PlatformDAO) FindDefault() (*model.Platform, error)

FindDefault 查找默认平台(not found 返回 nil,nil)。

func (*PlatformDAO) SetDefault

func (d *PlatformDAO) SetDefault(key string) error

SetDefault 设置默认平台(事务保证原子性:先清后设,不会出现无默认的窗口)

func (*PlatformDAO) Update

func (d *PlatformDAO) Update(platform *model.Platform) error

Update 更新平台

func (*PlatformDAO) UpdateFields

func (d *PlatformDAO) UpdateFields(key string, fields map[string]interface{}) error

UpdateFields 更新平台指定字段 注意:字段值原样写入;如需更新 access_token 请走 Update 以确保加密。

func (*PlatformDAO) UpdateRepoCount

func (d *PlatformDAO) UpdateRepoCount(platformID uint) error

UpdateRepoCount 更新平台关联的仓库数量

func (*PlatformDAO) UpdateStatus

func (d *PlatformDAO) UpdateStatus(key, status, testResult string) error

UpdateStatus 更新平台状态

type RepoDAO

type RepoDAO struct {
	// contains filtered or unexported fields
}

func NewRepoDAO

func NewRepoDAO(db *gorm.DB) (*RepoDAO, error)

func (*RepoDAO) BatchCreate

func (d *RepoDAO) BatchCreate(repos []*model.Repo, batchSize int) error

BatchCreate 批量创建仓库(用于同步场景,逐条加密后批量插入)。

func (*RepoDAO) BatchUpdateRepoMeta

func (d *RepoDAO) BatchUpdateRepoMeta(repos []*model.Repo) error

BatchUpdateRepoMeta 批量更新仓库元数据(路径/展示名/默认分支/clone URL)。 事务内用 map Updates,避免全字段回写覆盖加密 token/secret。

func (*RepoDAO) Count

func (d *RepoDAO) Count() (int64, error)

Count 返回仓库总数(走 COUNT 聚合,不加载行)。

func (*RepoDAO) CountByPlatformID

func (d *RepoDAO) CountByPlatformID(platformID uint) (int64, error)

CountByPlatformID 统计平台下的仓库数量(不加载数据,比 FindByPlatformID + len 高效)

func (*RepoDAO) Create

func (d *RepoDAO) Create(repo *model.Repo) error

func (*RepoDAO) Delete

func (d *RepoDAO) Delete(key string) error

func (*RepoDAO) FindAll

func (d *RepoDAO) FindAll(page Pagination) ([]*model.Repo, int64, error)

func (*RepoDAO) FindByCloneURL

func (d *RepoDAO) FindByCloneURL(cloneURL string) (*model.Repo, error)

FindByCloneURL 根据 Clone URL 查找仓库

func (*RepoDAO) FindByKey

func (d *RepoDAO) FindByKey(key string) (*model.Repo, error)

func (*RepoDAO) FindByPlatformAndRepo

func (d *RepoDAO) FindByPlatformAndRepo(platformID uint, platformRepo string) (*model.Repo, error)

FindByPlatformAndRepo 根据 platform_id + platform_repo 精确查找仓库。 比 FindByCloneURL 更可靠:私有部署实例地址重写后 CloneURL 会变, 但 (platform_id, platform_repo) 是稳定的业务主键。

func (*RepoDAO) FindByPlatformID

func (d *RepoDAO) FindByPlatformID(platformID uint) ([]*model.Repo, error)

FindByPlatformID 根据平台 ID 查找仓库

func (*RepoDAO) ListWithFilter

func (d *RepoDAO) ListWithFilter(page Pagination, filter *RepoFilter) ([]*model.Repo, int64, error)

ListWithFilter returns a filtered, sorted, paginated list of repos and the total count.

func (*RepoDAO) Update

func (d *RepoDAO) Update(repo *model.Repo) error

type RepoFilter

type RepoFilter struct {
	Search   string // search by name or clone_url (LIKE)
	Platform string // exact match on platform
	Status   string // exact match on status
	SortBy   string // column to sort by (default: created_at)
	OrderBy  string // sort direction: asc or desc (default: desc)
}

RepoFilter contains optional filters for listing repositories.

type StatsResult

type StatsResult struct {
	Today int64
	Week  int64
	Total int64
}

StatsResult 审计日志统计结果。

type SyncRunDAO

type SyncRunDAO struct {
	// contains filtered or unexported fields
}

func NewSyncRunDAO

func NewSyncRunDAO(db *gorm.DB) *SyncRunDAO

func (*SyncRunDAO) CleanupOlderThan

func (d *SyncRunDAO) CleanupOlderThan(ctx context.Context, olderThan time.Duration) (int64, error)

func (*SyncRunDAO) CountByTaskKey

func (d *SyncRunDAO) CountByTaskKey(taskKey string) (int64, error)

func (*SyncRunDAO) Create

func (d *SyncRunDAO) Create(run *model.SyncRun) error

func (*SyncRunDAO) DB

func (d *SyncRunDAO) DB() *gorm.DB

DB 返回底层 gorm.DB,供跨 DAO 事务使用。

func (*SyncRunDAO) Delete

func (d *SyncRunDAO) Delete(id uint) error

func (*SyncRunDAO) FindByIDWithSteps

func (d *SyncRunDAO) FindByIDWithSteps(id uint) (*model.SyncRun, error)

FindByIDWithSteps 单条详情查询,加载 Steps 子记录。

func (*SyncRunDAO) FindByTaskKey

func (d *SyncRunDAO) FindByTaskKey(taskKey string, page Pagination) ([]*model.SyncRun, int64, error)

FindByTaskKey 列表查询,不加载 Steps(列表页不需要步骤详情,避免 N+1)。

func (*SyncRunDAO) FindRecent

func (d *SyncRunDAO) FindRecent(page Pagination) ([]*model.SyncRun, error)

func (*SyncRunDAO) Update

func (d *SyncRunDAO) Update(run *model.SyncRun) error

type SyncRunStepDAO

type SyncRunStepDAO struct {
	// contains filtered or unexported fields
}

func NewSyncRunStepDAO

func NewSyncRunStepDAO(db *gorm.DB) *SyncRunStepDAO

func (*SyncRunStepDAO) CleanupOlderThan

func (d *SyncRunStepDAO) CleanupOlderThan(ctx context.Context, olderThan time.Duration) (int64, error)

func (*SyncRunStepDAO) Create

func (d *SyncRunStepDAO) Create(step *model.SyncRunStep) error

func (*SyncRunStepDAO) FindByRunID

func (d *SyncRunStepDAO) FindByRunID(runID uint) ([]*model.SyncRunStep, error)

func (*SyncRunStepDAO) Update

func (d *SyncRunStepDAO) Update(step *model.SyncRunStep) error

type SyncTaskDAO

type SyncTaskDAO struct {
	// contains filtered or unexported fields
}

func NewSyncTaskDAO

func NewSyncTaskDAO(db *gorm.DB) *SyncTaskDAO

func (*SyncTaskDAO) CountByStatus

func (d *SyncTaskDAO) CountByStatus() (map[string]int64, error)

CountByStatus 按_last_status 聚合计数,返回 map[status]count; 总数放在 "total" 键。用于面板计数,避免全表加载进内存。

func (*SyncTaskDAO) Create

func (d *SyncTaskDAO) Create(task *model.SyncTask) error

func (*SyncTaskDAO) Delete

func (d *SyncTaskDAO) Delete(key string) error

func (*SyncTaskDAO) FindAll

func (d *SyncTaskDAO) FindAll(page Pagination) ([]*model.SyncTask, int64, error)

func (*SyncTaskDAO) FindAllEnabled

func (d *SyncTaskDAO) FindAllEnabled() ([]*model.SyncTask, error)

func (*SyncTaskDAO) FindByKey

func (d *SyncTaskDAO) FindByKey(key string) (*model.SyncTask, error)

func (*SyncTaskDAO) FindByRepoKey

func (d *SyncTaskDAO) FindByRepoKey(repoKey string, page Pagination) ([]*model.SyncTask, int64, error)

func (*SyncTaskDAO) Update

func (d *SyncTaskDAO) Update(task *model.SyncTask) error

type WebhookEventDAO

type WebhookEventDAO struct {
	// contains filtered or unexported fields
}

func NewWebhookEventDAO

func NewWebhookEventDAO(db *gorm.DB) *WebhookEventDAO

func (*WebhookEventDAO) CleanupOlderThan

func (d *WebhookEventDAO) CleanupOlderThan(ctx context.Context, olderThan time.Duration) (int64, error)

func (*WebhookEventDAO) CountByRepoKey

func (d *WebhookEventDAO) CountByRepoKey(repoKey string) (int64, error)

func (*WebhookEventDAO) Create

func (d *WebhookEventDAO) Create(event *model.WebhookEvent) error

func (*WebhookEventDAO) FindByEventID

func (d *WebhookEventDAO) FindByEventID(eventID string) (*model.WebhookEvent, error)

func (*WebhookEventDAO) FindByID

func (d *WebhookEventDAO) FindByID(id uint) (*model.WebhookEvent, error)

func (*WebhookEventDAO) FindByRepoKey

func (d *WebhookEventDAO) FindByRepoKey(repoKey string, page Pagination) ([]*model.WebhookEvent, int64, error)

func (*WebhookEventDAO) FindRecent

func (d *WebhookEventDAO) FindRecent(repoKey string, page Pagination) ([]*model.WebhookEvent, error)

func (*WebhookEventDAO) Update

func (d *WebhookEventDAO) Update(event *model.WebhookEvent) error

func (*WebhookEventDAO) UpdateStatus

func (d *WebhookEventDAO) UpdateStatus(id uint, status string, processedAt *time.Time) error

UpdateStatus 仅更新 status 和 processed_at 字段,避免全字段回写(payload 可能很大)。

type WebhookRuleDAO

type WebhookRuleDAO struct {
	// contains filtered or unexported fields
}

func NewWebhookRuleDAO

func NewWebhookRuleDAO(db *gorm.DB) *WebhookRuleDAO

func (*WebhookRuleDAO) Create

func (d *WebhookRuleDAO) Create(rule *model.WebhookRule) error

func (*WebhookRuleDAO) Delete

func (d *WebhookRuleDAO) Delete(id uint) error

func (*WebhookRuleDAO) FindByID

func (d *WebhookRuleDAO) FindByID(id uint) (*model.WebhookRule, error)

func (*WebhookRuleDAO) FindByRepoKey

func (d *WebhookRuleDAO) FindByRepoKey(repoKey string) ([]*model.WebhookRule, error)

func (*WebhookRuleDAO) FindTasksByRuleID

func (d *WebhookRuleDAO) FindTasksByRuleID(ruleID uint) ([]model.WebhookRuleTask, error)

func (*WebhookRuleDAO) Update

func (d *WebhookRuleDAO) Update(rule *model.WebhookRule) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL