idempotencystore

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 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)
	field0 := table.Key()
	field1 := orm.TextOf(b, &m.Namespace)
	field2 := orm.TextOf(b, &m.Operation)
	field3 := orm.NumberOf(b, &m.Version)
	field4 := orm.TextOf(b, &m.ScopeDigest)
	field5 := orm.TextOf(b, &m.KeyDigest)
	field6 := orm.TextOf(b, &m.Fingerprint)
	field7 := orm.TextOf(b, &m.ResultSchema)
	field8 := orm.TextOf(b, &m.ResultHash)
	field9 := orm.BytesOf(b, &m.Representation)
	field10 := orm.NullableTimeOf(b, &m.CompletedAt)
	field11 := orm.NullableTimeOf(b, &m.ExpiresAt)
	return RecordTable{
		Table:          table,
		ID:             field0,
		Namespace:      field1,
		Operation:      field2,
		Version:        field3,
		ScopeDigest:    field4,
		KeyDigest:      field5,
		Fingerprint:    field6,
		ResultSchema:   field7,
		ResultHash:     field8,
		Representation: field9,
		CompletedAt:    field10,
		ExpiresAt:      field11,
	}
}, orm.ModelFingerprint("1e8483f72bde9473d214293a210d62ea0b06d98b0afcfaf05ce3dddc5b7a9763"))

Records is the foundry_idempotency table.

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 {
	// Table provides Record queries and writes. Example: Records.Query().Limit(10).
	//
	// ID binds the persisted Record.ID column.
	// Example: orm.Eq(Records.ID, id).
	ID model.ID[Record] `foundry:"member=ID"`
	// Namespace binds the persisted Record.Namespace column.
	// Example: orm.Set(Records.Namespace, namespace).
	Namespace string
	// Operation binds the persisted Record.Operation column.
	// Example: orm.Set(Records.Operation, operation).
	Operation string
	// Version binds the persisted Record.Version column.
	// Example: orm.Set(Records.Version, version).
	Version uint32
	// ScopeDigest binds the persisted Record.ScopeDigest column.
	// Example: orm.Set(Records.ScopeDigest, scopeDigest).
	ScopeDigest string
	// KeyDigest binds the persisted Record.KeyDigest column.
	// Example: orm.Set(Records.KeyDigest, keyDigest).
	KeyDigest string
	// Fingerprint binds the persisted Record.Fingerprint column.
	// Example: orm.Set(Records.Fingerprint, fingerprint).
	Fingerprint string
	// ResultSchema binds the persisted Record.ResultSchema column.
	// Example: orm.Set(Records.ResultSchema, resultSchema).
	ResultSchema string `foundry:"default=database"`
	// ResultHash binds the persisted Record.ResultHash column.
	// Example: orm.Set(Records.ResultHash, resultHash).
	ResultHash string `foundry:"default=database"`
	// Representation binds the persisted Record.Representation column.
	// Example: orm.Set(Records.Representation, representation).
	Representation []byte `foundry:"default=database"`
	// CompletedAt binds the persisted Record.CompletedAt column.
	// Example: orm.SetNull(Records.CompletedAt).
	CompletedAt value.Nullable[temporal.DateTime]
	// ExpiresAt binds the persisted Record.ExpiresAt column.
	// Example: orm.SetNull(Records.ExpiresAt).
	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).
	//
	// ID binds the persisted Record.ID column.
	// Example: orm.Eq(Records.ID, id).
	//
	// See [Record.ID].
	orm.Table[Record, model.ID[Record]]
	//
	// Table provides Record queries and writes. Example: Records.Query().Limit(10).
	//
	// ID binds the persisted Record.ID column.
	// Example: orm.Eq(Records.ID, id).
	//
	// See [Record.ID].
	ID orm.Key[Record, model.ID[Record]]
	//
	// Namespace binds the persisted Record.Namespace column.
	// Example: orm.Set(Records.Namespace, namespace).
	//
	// See [Record.Namespace].
	Namespace orm.Text[Record, string]
	//
	// Operation binds the persisted Record.Operation column.
	// Example: orm.Set(Records.Operation, operation).
	//
	// See [Record.Operation].
	Operation orm.Text[Record, string]
	//
	// Version binds the persisted Record.Version column.
	// Example: orm.Set(Records.Version, version).
	//
	// See [Record.Version].
	Version orm.Number[Record, uint32]
	//
	// ScopeDigest binds the persisted Record.ScopeDigest column.
	// Example: orm.Set(Records.ScopeDigest, scopeDigest).
	//
	// See [Record.ScopeDigest].
	ScopeDigest orm.Text[Record, string]
	//
	// KeyDigest binds the persisted Record.KeyDigest column.
	// Example: orm.Set(Records.KeyDigest, keyDigest).
	//
	// See [Record.KeyDigest].
	KeyDigest orm.Text[Record, string]
	//
	// Fingerprint binds the persisted Record.Fingerprint column.
	// Example: orm.Set(Records.Fingerprint, fingerprint).
	//
	// See [Record.Fingerprint].
	Fingerprint orm.Text[Record, string]
	//
	// ResultSchema binds the persisted Record.ResultSchema column.
	// Example: orm.Set(Records.ResultSchema, resultSchema).
	//
	// See [Record.ResultSchema].
	ResultSchema orm.Text[Record, string]
	//
	// ResultHash binds the persisted Record.ResultHash column.
	// Example: orm.Set(Records.ResultHash, resultHash).
	//
	// See [Record.ResultHash].
	ResultHash orm.Text[Record, string]
	//
	// Representation binds the persisted Record.Representation column.
	// Example: orm.Set(Records.Representation, representation).
	//
	// See [Record.Representation].
	Representation orm.Column[Record, []byte]
	//
	// CompletedAt binds the persisted Record.CompletedAt column.
	// Example: orm.SetNull(Records.CompletedAt).
	//
	// See [Record.CompletedAt].
	CompletedAt orm.NullableTime[Record, temporal.DateTime]
	//
	// ExpiresAt binds the persisted Record.ExpiresAt column.
	// Example: orm.SetNull(Records.ExpiresAt).
	//
	// See [Record.ExpiresAt].
	ExpiresAt orm.NullableTime[Record, temporal.DateTime]
}

RecordTable binds the declared fields of Record.

Jump to

Keyboard shortcuts

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