idempotencystore

package
v0.50.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 7 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 idempotencystore owns typed operation persistence. Rows are never public DTOs; the operation's concrete result codec validates stored bytes.

Index

Constants

This section is empty.

Variables

View Source
var Records = orm.Define("foundry_idempotency", func(b orm.Builder[Record], m *Record) RecordTable {
	table := orm.TableOf(b, &m.ID)
	return RecordTable{Table: table,
		ID:             table.Key(),
		Namespace:      orm.TextOf(b, &m.Namespace),
		Operation:      orm.TextOf(b, &m.Operation),
		Version:        orm.NumberOf(b, &m.Version),
		ScopeDigest:    orm.TextOf(b, &m.ScopeDigest),
		KeyDigest:      orm.TextOf(b, &m.KeyDigest),
		Fingerprint:    orm.TextOf(b, &m.Fingerprint),
		ResultSchema:   orm.TextOf(b, &m.ResultSchema),
		ResultHash:     orm.TextOf(b, &m.ResultHash),
		Representation: orm.BytesOf(b, &m.Representation),
		CompletedAt:    orm.NullableTimeOf(b, &m.CompletedAt),
		ExpiresAt:      orm.NullableTimeOf(b, &m.ExpiresAt),
	}
})

Records owns the immutable Record declaration. Example: orm.First(ctx, tx, Records.Query()).

Functions

func Claim

func Claim(ctx context.Context, tx *database.Tx, a Address, fingerprint string) (value.Optional[Record], error)

Claim uses one INSERT with a unique arbiter. A skipped insert must be followed by a fresh statement at Read Committed, never interpreted as a missing row.

func Complete

func Complete(ctx context.Context, tx *database.Tx, row Record, schema, hash string, data []byte, completed, expires temporal.DateTime) error

func CountRetained

func CountRetained(ctx context.Context, tx *database.Tx, a Address, now temporal.DateTime, limit int) (int64, error)

CountRetained counts the caller's committed outcomes that are unexpired at now, stopping at limit. Uncommitted claims of other transactions are not visible; the caller's own claim has no expiry and is not counted. The index on (namespace, scope_digest, expires_at) bounds the read to limit rows.

func Find

func Find(ctx context.Context, tx *database.Tx, a Address) (value.Optional[Record], error)

Types

type Address

type Address struct {
	Namespace, Operation string
	Version              uint32
	Scope, Key           string
}

type Record

type Record struct {
	ID             model.ID[Record]
	Namespace      string
	Operation      string
	Version        uint32
	ScopeDigest    string
	KeyDigest      string
	Fingerprint    string
	ResultSchema   string `foundry:"default=database"`
	ResultHash     string `foundry:"default=database"`
	Representation []byte `foundry:"default=database"`
	CompletedAt    value.Nullable[temporal.DateTime]
	ExpiresAt      value.Nullable[temporal.DateTime]
}

func (Record) Format

func (Record) Format(s fmt.State, _ rune)

type RecordTable

type RecordTable struct {
	// Table provides Record queries and writes. Example: Records.Query().Limit(10).
	orm.Table[Record, model.ID[Record]]
	// ID binds the persisted Record.ID column.
	// Example: orm.Eq(Records.ID, id).
	ID orm.Key[Record, model.ID[Record]]
	// Namespace binds the persisted Record.Namespace column.
	// Example: orm.Set(Records.Namespace, namespace).
	Namespace orm.Text[Record, string]
	// Operation binds the persisted Record.Operation column.
	// Example: orm.Set(Records.Operation, operation).
	Operation orm.Text[Record, string]
	// Version binds the persisted Record.Version column.
	// Example: orm.Set(Records.Version, version).
	Version orm.Number[Record, uint32]
	// ScopeDigest binds the persisted Record.ScopeDigest column.
	// Example: orm.Set(Records.ScopeDigest, scopeDigest).
	ScopeDigest orm.Text[Record, string]
	// KeyDigest binds the persisted Record.KeyDigest column.
	// Example: orm.Set(Records.KeyDigest, keyDigest).
	KeyDigest orm.Text[Record, string]
	// Fingerprint binds the persisted Record.Fingerprint column.
	// Example: orm.Set(Records.Fingerprint, fingerprint).
	Fingerprint orm.Text[Record, string]
	// ResultSchema binds the persisted Record.ResultSchema column.
	// Example: orm.Set(Records.ResultSchema, resultSchema).
	ResultSchema orm.Text[Record, string]
	// ResultHash binds the persisted Record.ResultHash column.
	// Example: orm.Set(Records.ResultHash, resultHash).
	ResultHash orm.Text[Record, string]
	// Representation binds the persisted Record.Representation column.
	// Example: orm.Set(Records.Representation, representation).
	Representation orm.Column[Record, []byte]
	// CompletedAt binds the persisted Record.CompletedAt column.
	// Example: orm.SetNull(Records.CompletedAt).
	CompletedAt orm.NullableTime[Record, temporal.DateTime]
	// ExpiresAt binds the persisted Record.ExpiresAt column.
	// Example: orm.SetNull(Records.ExpiresAt).
	ExpiresAt orm.NullableTime[Record, temporal.DateTime]
}

RecordTable binds the persisted Record columns. Example: Records.Query().Limit(10).

Jump to

Keyboard shortcuts

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