postgres

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 25 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres implements Knowl operational state and search projections with PostgreSQL-native transactions and full-text search.

Package postgres implements Knowl operational state and search projections with PostgreSQL-native transactions and full-text search.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConflict           = errors.New("knowl operation conflict")
	ErrNotFound           = app.ErrOperationNotFound
	ErrInvalidState       = errors.New("knowl operation state transition is invalid")
	ErrLeaseConflict      = app.ErrApplyLeaseConflict
	ErrInvalidQuery       = errors.New("knowl search query is invalid")
	ErrProjectionNotReady = errors.New("knowl projection is not ready")
	ErrProjectionDrift    = errors.New("knowl projection drift detected")
	ErrInvalidProjection  = lexical.ErrInvalidProjection
)

Functions

This section is empty.

Types

type ProjectionState

type ProjectionState struct {
	Scope          knowl.ScopeRef
	SchemaDigest   string
	SnapshotDigest string
	PageCount      int
	LinkCount      int
	ReadyAt        time.Time
}

ProjectionState describes the last canonical snapshot projected for a scope.

type Store

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

Store implements app.OperationStore and app.SearchIndex.

func Open

func Open(ctx context.Context, dsn string, options ...app.EmbeddingOptions) (*Store, error)

Open opens a PostgreSQL operational store and runs its embedded migrations.

func (*Store) BeginSync added in v0.3.0

func (store *Store) BeginSync(ctx context.Context, request app.BeginSyncRequest) (knowl.SyncRun, bool, error)

func (*Store) CheckProjection

func (store *Store) CheckProjection(ctx context.Context, snapshot knowl.WorkspaceSnapshot) error

func (*Store) ClaimOperation added in v0.4.0

func (store *Store) ClaimOperation(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID, lease knowl.WorkLease) (knowl.WorkClaim, error)

ClaimOperation atomically grants a work lease for one specific claimable operation.

func (*Store) ClaimReady

func (store *Store) ClaimReady(ctx context.Context, scope knowl.ScopeRef, lease knowl.WorkLease) (knowl.WorkClaim, error)

ClaimReady atomically grants a work lease using database-level row locking.

func (*Store) Close

func (store *Store) Close() error

Close closes the underlying database connection pool.

func (*Store) CommitOutcome

func (store *Store) CommitOutcome(ctx context.Context, id knowl.OperationID, commit knowl.ContentCommit) error

CommitOutcome marks a canonical content commit as complete.

func (*Store) DSN

func (store *Store) DSN() string

DSN returns the configured connection string.

func (*Store) DescriptorFailures

func (store *Store) DescriptorFailures(ctx context.Context, scope knowl.ScopeRef, limit int) ([]knowl.OperationID, error)

DescriptorFailures lists non-terminal operations whose durable inputs cannot be validated.

func (*Store) DocumentState added in v0.3.0

func (store *Store) DocumentState(ctx context.Context, scope knowl.ScopeRef, sourceID knowl.SourceID, documentID knowl.DocumentID) (knowl.DocumentState, error)

func (*Store) DocumentStates added in v0.3.0

func (store *Store) DocumentStates(ctx context.Context, scope knowl.ScopeRef, sourceID knowl.SourceID, options app.DocumentListOptions) ([]knowl.DocumentState, error)

func (*Store) Execution

func (store *Store) Execution(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID) (knowl.ExecutionDescriptor, error)

Execution returns the validated durable descriptor for one scoped operation.

func (*Store) Fail

func (store *Store) Fail(ctx context.Context, id knowl.OperationID, failure knowl.Failure) error

Fail records stable redacted failure metadata.

func (*Store) FailClaim added in v0.4.0

func (store *Store) FailClaim(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID, token string, failure knowl.Failure) error

FailClaim terminalizes work only while the caller still owns a live lease.

func (*Store) FailSync added in v0.3.0

func (store *Store) FailSync(ctx context.Context, scope knowl.ScopeRef, id knowl.SyncRunID, failureClass string, failedAt time.Time) (knowl.SyncRun, error)

func (*Store) FinalizeSync added in v0.3.0

func (store *Store) FinalizeSync(ctx context.Context, finalization app.SyncFinalization) (knowl.SyncRun, error)
func (store *Store) Links(ctx context.Context, scope knowl.ScopeRef, page knowl.PageID, limits knowl.ReadLimits) ([]knowl.LinkReference, error)

Links returns bounded, untrusted graph references.

func (*Store) ListOperations added in v0.6.0

ListOperations reads bounded summaries in immutable creation order.

func (*Store) ListSourceDocuments added in v0.6.0

ListSourceDocuments reads saved heads and tombstones in bytewise document order.

func (*Store) MaintenanceRetrievalPolicy added in v0.6.0

func (store *Store) MaintenanceRetrievalPolicy() *app.MaintenanceRetrievalPolicy

func (*Store) MarkApplying

func (store *Store) MarkApplying(ctx context.Context, id knowl.OperationID, lease knowl.Lease) error

MarkApplying claims an operation with a lease.

func (*Store) MarkAwaitingReview

func (store *Store) MarkAwaitingReview(ctx context.Context, id knowl.OperationID) error

MarkAwaitingReview marks an operation that needs explicit apply.

func (*Store) MarkContentCommitted added in v0.3.0

func (store *Store) MarkContentCommitted(ctx context.Context, generation app.SyncGeneration) (knowl.SyncRun, error)

func (*Store) MarkProjected added in v0.3.0

func (store *Store) MarkProjected(ctx context.Context, generation app.SyncGeneration) (knowl.SyncRun, error)

func (*Store) Operation

func (store *Store) Operation(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID) (knowl.Operation, error)

Operation reads one operation within its scope.

func (*Store) PrepareSync added in v0.3.0

func (store *Store) PrepareSync(ctx context.Context, prepared app.PreparedSyncState) (knowl.SyncRun, error)

func (*Store) PreparedSync added in v0.3.0

func (store *Store) PreparedSync(ctx context.Context, scope knowl.ScopeRef, id knowl.SyncRunID) (app.PreparedSyncRead, error)

func (*Store) Project

func (store *Store) Project(ctx context.Context, commit knowl.ContentCommit) error

Project indexes a canonical content commit snapshot.

func (*Store) ProjectWithoutInference added in v0.6.0

func (store *Store) ProjectWithoutInference(ctx context.Context, commit knowl.ContentCommit) error

ProjectWithoutInference finishes an existing historical stage without calling a model introduced by a newer policy. Its dense projection requires repair.

func (*Store) ProjectionDegraded added in v0.6.0

func (store *Store) ProjectionDegraded(ctx context.Context, scope knowl.ScopeRef) (bool, error)

ProjectionDegraded permits one startup repair attempt even when the current fallback policy accepts a durable current-snapshot degraded projection.

func (*Store) ProjectionStatus

func (store *Store) ProjectionStatus(ctx context.Context, scope knowl.ScopeRef) (ProjectionState, error)

ProjectionStatus returns readiness metadata for a scope.

func (*Store) Rebuild

func (store *Store) Rebuild(ctx context.Context, snapshot knowl.WorkspaceSnapshot) error

func (*Store) RecordScanPage added in v0.3.0

func (store *Store) RecordScanPage(ctx context.Context, record app.ScanPageRecord) (knowl.SyncRun, error)

func (*Store) ReleaseClaim

func (store *Store) ReleaseClaim(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID, token string) error

ReleaseClaim makes owned non-terminal work immediately ready again.

func (*Store) RenewClaim

func (store *Store) RenewClaim(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID, currentToken string, next knowl.WorkLease) error

RenewClaim replaces a live work lease when the caller still owns its token.

func (*Store) Reserve

func (store *Store) Reserve(ctx context.Context, key knowl.OperationKey, meta knowl.OperationMeta) (app.OperationReservation, error)

Reserve creates or returns the operation for one source revision.

func (*Store) ReserveOperation added in v0.4.0

func (store *Store) ReserveOperation(ctx context.Context, identity knowl.OperationIdentity, descriptor knowl.ExecutionDescriptor) (app.OperationReservation, error)

ReserveOperation creates or replays one generic hierarchy operation.

func (*Store) ResumableSyncRuns added in v0.3.0

func (store *Store) ResumableSyncRuns(ctx context.Context, scope knowl.ScopeRef, limit int) ([]knowl.SyncRun, error)

func (*Store) ResumeReady

func (store *Store) ResumeReady(ctx context.Context, scope knowl.ScopeRef, limit int) ([]knowl.OperationID, error)

ResumeReady lists bounded claimable operation IDs without granting ownership.

func (*Store) RetrySourceMaintenance added in v0.4.0

func (store *Store) RetrySourceMaintenance(ctx context.Context, request app.SourceMaintenanceRetryRequest) (app.SourceMaintenanceRetryResult, error)

RetrySourceMaintenance atomically previews or requeues selected terminal current-revision source maintenance operations.

func (*Store) SaveOperationContextReport added in v0.6.0

func (store *Store) SaveOperationContextReport(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID, attempt int, report knowl.OperationContextReport) error

SaveOperationContextReport persists one immutable snapshot for a work attempt.

func (*Store) SaveOperationCorrectionReport added in v0.6.0

func (store *Store) SaveOperationCorrectionReport(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID, attempt int, report knowl.OperationCorrectionReport) error

SaveOperationCorrectionReport persists one immutable snapshot for a work attempt.

func (*Store) SavePlan

func (store *Store) SavePlan(ctx context.Context, id knowl.OperationID, summary knowl.PlanSummary) error

SavePlan persists a redacted plan digest and advances the operation.

func (*Store) SaveRetrievalReport added in v0.6.0

func (store *Store) SaveRetrievalReport(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID, attempt int, report knowl.RetrievalReport) error

SaveRetrievalReport records a bounded report for the current worker attempt. Replays are idempotent; a terminal operation or newer attempt is immutable.

func (*Store) ScanDocuments added in v0.3.0

func (store *Store) ScanDocuments(ctx context.Context, scope knowl.ScopeRef, id knowl.SyncRunID, limit int) ([]knowl.DocumentRef, error)

func (*Store) ScheduleRetry added in v0.4.0

func (store *Store) ScheduleRetry(ctx context.Context, scope knowl.ScopeRef, id knowl.OperationID, token string, failure knowl.Failure, readyAt time.Time) error

ScheduleRetry records a safe transient failure and delays work owned by the current lease holder. The operation remains non-terminal.

func (*Store) Search

func (store *Store) Search(ctx context.Context, scope knowl.ScopeRef, query string, limits knowl.ReadLimits, sources []knowl.SourceID) ([]knowl.PageReference, error)

Search returns bounded, untrusted PostgreSQL full-text references.

func (*Store) SearchWithReport added in v0.6.0

func (store *Store) SearchWithReport(ctx context.Context, scope knowl.ScopeRef, query string, limits knowl.ReadLimits, sources []knowl.SourceID) ([]knowl.PageReference, knowl.RetrievalReport, error)

func (*Store) SelectContext

func (store *Store) SelectContext(ctx context.Context, scope knowl.ScopeRef, source knowl.SourceSummary, limits knowl.ReadLimits) ([]knowl.PageID, error)

func (*Store) SelectContextWithDiagnostics added in v0.6.0

func (store *Store) SelectContextWithDiagnostics(ctx context.Context, scope knowl.ScopeRef, source knowl.SourceSummary, limits knowl.ReadLimits) ([]knowl.PageID, knowl.RetrievalReport, knowl.ContextSelectionDiagnostics, error)

SelectContextWithDiagnostics reports facts from the same selection pass.

func (*Store) SelectContextWithReport added in v0.6.0

func (store *Store) SelectContextWithReport(ctx context.Context, scope knowl.ScopeRef, source knowl.SourceSummary, limits knowl.ReadLimits) ([]knowl.PageID, knowl.RetrievalReport, error)

func (*Store) SourceStatus added in v0.3.0

func (store *Store) SourceStatus(ctx context.Context, scope knowl.ScopeRef, sourceID knowl.SourceID) (knowl.SourceStatus, error)

func (*Store) SyncRun added in v0.3.0

func (store *Store) SyncRun(ctx context.Context, scope knowl.ScopeRef, id knowl.SyncRunID) (knowl.SyncRun, error)

Jump to

Keyboard shortcuts

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