sqlstore

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 16 Imported by: 0 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 sqlstore owns SQL schema details for durable human requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SchemaStatements

func SchemaStatements(dialect db.Dialect) ([]string, error)

SchemaStatements returns additive request tables and indexes for a tenant database. Tenant identity is retained in each row even though each tenant has a separate database, so moving/querying records cannot silently erase the security boundary.

Types

type DirectTaskAuthorizer

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

DirectTaskAuthorizer implements the policy for direct, subject-free user tasks. It deliberately does not authorize governed approvals, role/group expansion, or subject-bound requests; those decisions belong to a domain policy provider.

func NewDirectTaskAuthorizer

func NewDirectTaskAuthorizer(database *sql.DB, dialect db.QueryDialect) (*DirectTaskAuthorizer, error)

func (*DirectTaskAuthorizer) Management

func (*DirectTaskAuthorizer) Submission

func (*DirectTaskAuthorizer) Visibility

type Store

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

Store persists request data in the tenant database. It is deliberately not an HTTP service: callers must authorize and project records before exposing them. Create commits the request, assignment snapshot, history, outbox events and retry receipt in one SQL transaction.

func New

func New(database *sql.DB, dialect db.Dialect) (*Store, error)

func (*Store) Cancel

Cancel atomically closes a pending request, stops outstanding assignments, appends history/events and stores the retry receipt. Policy authorization is evaluated by the service and fenced by the authorization epochs here.

func (*Store) CommitDecision

func (s *Store) CommitDecision(ctx context.Context, change requests.DecisionCommit) (contract.ResponseReceipt, error)

CommitDecision durably records one authorized assignment response. It locks the tenant authorization epochs and request row, then updates the decision, quorum state, history, outbox and idempotency receipt in one transaction. The caller must re-evaluate actor eligibility and subject visibility before constructing this commit; the epochs make that check stable through commit.

func (*Store) CommitDecisionInTx

func (s *Store) CommitDecisionInTx(ctx context.Context, tx *sql.Tx, change requests.DecisionCommit) (contract.ResponseReceipt, error)

CommitDecisionInTx performs the response using the transaction owned by a composition-layer unit of work. The caller is responsible for commit or rollback; no second connection is acquired by this method.

func (*Store) Create

Create atomically records a newly authorized submission. Authorization snapshots are supplied by the request service; this method validates their binding and makes every local durable effect commit or roll back together.

func (*Store) CreateInTx

func (s *Store) CreateInTx(ctx context.Context, tx *sql.Tx, change requests.CreateCommit) (requests.RequestRecord, error)

CreateInTx appends the request, assignment snapshot, history, event outbox, and idempotency receipt to the caller's transaction. It deliberately leaves transaction ownership with the caller.

func (*Store) DirectTaskNotificationRecipients

func (s *Store) DirectTaskNotificationRecipients(ctx context.Context, tenant contract.TenantID, site string, requestID contract.RequestID, eventType string) ([]contract.PrincipalID, error)

DirectTaskNotificationRecipients resolves only the small, current set of active direct-task participants. It returns identifiers, never request content; later notification delivery remains a recipient-scoped invalidation and the request API rechecks visibility when the client refetches.

func (*Store) ExpireDue

func (s *Store) ExpireDue(ctx context.Context, tenant contract.TenantID, limit uint16) (uint16, error)

ExpireDue closes a bounded batch of requests whose deadline has passed. The database clock is sampled in the selection query and reused for every write so workers on differently skewed hosts agree with response/cancellation checks. Each terminal state, assignment cancellation, history record and outbox event is committed in one transaction.

func (*Store) Get

Get loads the current durable record. Visibility and field authorization are intentionally enforced by the request service before projection.

func (*Store) History

History returns a stable sequence page only when the verified visibility scope contains the requester, a current assigned participant, or a manager. A missing and an unauthorized request both return NotFound.

func (*Store) ListVisible

ListVisible returns a bounded keyset page. The cursor is bound to the tenant, actor, manager scope and every filter; SQL independently enforces row visibility on every page.

func (*Store) LookupResponseReceipt

func (s *Store) LookupResponseReceipt(ctx context.Context, identity requests.WriteIdentity) (contract.ResponseReceipt, bool, error)

LookupResponseReceipt is the public request-service seam for resolving a same-command retry before checking the now-completed assignment again.

func (*Store) MarkRead

func (s *Store) MarkRead(ctx context.Context, scope requests.VisibilityScope, id contract.RequestID) error

MarkRead stores a per-principal watermark. It deliberately does not change request state or emit a completion event. Visibility authorization is done by the service before this storage operation.

func (*Store) MarkStale

func (s *Store) MarkStale(ctx context.Context, tenant contract.TenantID, id contract.RequestID, expected contract.Revision, observed contract.SubjectRef) error

MarkStale persists the terminal transition after the caller has observed a different live subject revision. It refuses to stale an unrelated or already terminal request and records no subject content in the event payload.

func (*Store) Reassign

Reassign atomically transfers a pending assignment, records the immutable history entry, publishes invalidations and stores the retry receipt.

func (*Store) Response

func (s *Store) Response(ctx context.Context, scope requests.VisibilityScope, requestID contract.RequestID, decisionID contract.DecisionID) (requests.DecisionRecord, error)

Response returns a stored decision only for a requester, current assigned participant or explicit manager. It deliberately leaves information schema validation and field-level projection to the authorized request service.

Jump to

Keyboard shortcuts

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