Files
knowledge-governance/internal/dobotaiops/record_repository.go
T
姚章浩 00c4c13283
build / build (push) Successful in 1m19s
fix(qa): 首批即显并统一五字段后端筛选
列表正文改为按需读取;保留完整导出、版本隔离和有效标签筛选。
验证:前端全量、Go全量及隔离PG全mirror竞态通过;覆盖首批回调、续载失败与筛选分页。
2026-10-25 12:45:31 +08:00

65 lines
2.5 KiB
Go

package dobotaiops
import (
"context"
"time"
)
// RecordQuerier and RecordTransaction keep the projection identical while an
// explicitly selected reader supplies either source-ACL or local-snapshot transactions.
type RecordRow = rowScanner
type RecordQuerier = querier
type RecordTransaction func(context.Context, func(context.Context, RecordQuerier) error) error
type RecordsRepositoryOptions struct {
BaseSQL string
SummarySQL string
QualityScopeSQL string
Transaction RecordTransaction
ValidateWindow func(Window) error
ReadAsOf func(context.Context, RecordQuerier, *time.Time) error
TenantKey string
}
type RecordsRepository struct {
baseSQL string
summarySQL string
qualityScopeSQL string
transact RecordTransaction
validateQueryWindow func(Window) error
readAsOf func(context.Context, RecordQuerier, *time.Time) error
tenant string
}
func NewRecordsRepository(o RecordsRepositoryOptions) *RecordsRepository {
asOf := o.ReadAsOf
if asOf == nil {
asOf = func(ctx context.Context, q RecordQuerier, t *time.Time) error {
return q.QueryRow(ctx, "SELECT transaction_timestamp()").Scan(t)
}
}
return &RecordsRepository{summarySQL: o.SummarySQL, qualityScopeSQL: o.QualityScopeSQL, baseSQL: o.BaseSQL, transact: o.Transaction, validateQueryWindow: o.ValidateWindow, readAsOf: asOf, tenant: o.TenantKey}
}
func (c *RecordsRepository) WithSummarySQL(sql string) *RecordsRepository {
out := *c
out.summarySQL = sql
return &out
}
func (c *Client) recordRepository() *RecordsRepository {
return NewRecordsRepository(RecordsRepositoryOptions{BaseSQL: recordsBaseSQL, Transaction: c.withReadOnlyTx, ValidateWindow: c.validateQueryWindow})
}
func (c *Client) ListRecords(ctx context.Context, q RecordQuery) (RecordPage, error) {
return c.recordRepository().ListRecords(ctx, q)
}
func (c *Client) GetRecord(ctx context.Context, tenant, id string) (Record, error) {
return c.recordRepository().GetRecord(ctx, tenant, id)
}
func (c *Client) ReadUsageGroups(ctx context.Context, q RecordQuery) (UsageGroups, error) {
return c.recordRepository().ReadUsageGroups(ctx, q)
}
func (c *Client) ReadQualityScope(ctx context.Context, q RecordQuery) (QualityScope, error) {
return c.recordRepository().ReadQualityScope(ctx, q)
}
// DecodeMirrorPayload accepts only the source adapter's fixed safe projection;
// credentials and arbitrary source tables are never part of this protocol.
func DecodeMirrorPayload(raw string) (Record, error) { return decodeRecord(raw) }