bunstore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package bunstore implements b2bua.Store using Bun over database/sql for managed durable continuity (PostgreSQL) and for dialect-backed tests (SQLite).

It is a concrete adapter: Bun types and SQL stay inside this package.

Schema evolution: migrations are applied with github.com/uptrace/bun/migrate using adapter-local Go migration functions registered from schema.go (sync.Once). The baseline uses CREATE IF NOT EXISTS so existing databases created before migration history still converge safely; the first successful run records migration BaselineMigrationName in table bun_continuity_migrations. Down migrations are no-ops by design.

Index

Constants

View Source
const BaselineMigrationName = "20250426000000"

BaselineMigrationName is the name bun/migrate records for this adapter's baseline (file prefix).

View Source
const ConversationViewMigrationName = "20260814000000"

ConversationViewMigrationName is the bun/migrate name for the conversation-view tables (file prefix).

View Source
const InterleavedStateMigrationName = "20250427000000"

InterleavedStateMigrationName is the bun/migrate name for the interleaved thinking state column addition (file prefix).

View Source
const RouteOverrideMigrationName = "20260813000000"

RouteOverrideMigrationName is the bun/migrate name for the A-leg route-override table (file prefix).

Variables

This section is empty.

Functions

func DecodeInterleavedStateRow

func DecodeInterleavedStateRow(encoded string) (interleavedstate.State, json.RawMessage, error)

DecodeInterleavedStateRow decodes an encoded database string (which may be a legacy row with memo_ref or a current row with cycle only) into the compatibility DTO, then projects only cycle values into core state and memo values outward.

func EncodeInterleavedStateRow

func EncodeInterleavedStateRow(dto LegacyInterleavedStateRowDTO) (string, error)

EncodeInterleavedStateRow encodes a compatibility DTO into a JSON string, preserving memo_ref alongside cycle state when present without feature algorithms in core.

func RunSchemaMigrate

func RunSchemaMigrate(ctx context.Context, db *bun.DB) error

RunSchemaMigrate runs the schema migrations for continuity against the provided DB.

Types

type LegacyInterleavedStateRowDTO

type LegacyInterleavedStateRowDTO struct {
	Cycle   interleavedstate.CycleState `json:"cycle"`
	MemoRef json.RawMessage             `json:"memo_ref,omitempty"`
}

LegacyInterleavedStateRowDTO represents the durable storage format that preserves memo_ref alongside cycle state across legacy and current database rows without executing feature algorithms in core.

type Store

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

Store persists A-leg rows, B-leg allocations, and attempt lineage using Bun.

func New

func New(db *bun.DB) (*Store, error)

New returns a Store backed by db after applying schema. Closing the store closes the underlying sql.DB. ctx bounds migrate DDL; use NewWithContext for explicit cancellation/timeouts.

func NewWithContext

func NewWithContext(ctx context.Context, db *bun.DB) (*Store, error)

NewWithContext returns a Store backed by db after applying schema, honoring ctx for migrate DDL.

func (*Store) Clear

func (s *Store) Clear(ctx context.Context, aLegID string, now time.Time) (routeoverride.State, error)

Clear deactivates the A-leg override. Already-inactive state is a no-op.

func (*Store) Close

func (s *Store) Close() error

Close releases the database handle.

func (*Store) CreateALeg

func (s *Store) CreateALeg(ctx context.Context, continuityKey string) (b2bua.ALegRecord, error)

func (*Store) DB

func (s *Store) DB() *bun.DB

DB returns the underlying bun.DB handle.

func (*Store) FetchALeg

func (s *Store) FetchALeg(ctx context.Context, aLegID string) (b2bua.ALegRecord, error)

func (*Store) FetchInterleavedRow

func (s *Store) FetchInterleavedRow(ctx context.Context, aLegID string) (LegacyInterleavedStateRowDTO, error)

FetchInterleavedRow returns the compatibility DTO containing both core cycle state and legacy memo_ref payload for an A-leg, preserving durable backward compatibility.

func (*Store) FetchInterleavedState

func (s *Store) FetchInterleavedState(ctx context.Context, aLegID string) (interleavedstate.State, error)

FetchInterleavedState returns the thinker cycle state for an A-leg. A leg with no stored state returns the zero value, which is a harmless "new session" state for cycle purposes.

func (*Store) FetchInterleavedStateRow

func (s *Store) FetchInterleavedStateRow(ctx context.Context, aLegID string) (interleavedstate.State, json.RawMessage, error)

FetchInterleavedStateRow returns the projected core cycle state and the raw memo_ref payload outward from durable storage.

func (*Store) Get

func (s *Store) Get(ctx context.Context, aLegID string) (routeoverride.State, error)

Get uses the same read semantics as Snapshot.

func (*Store) LoadAttempts

func (s *Store) LoadAttempts(ctx context.Context, aLegID string) (out []lipapi.AttemptRecord, err error)

func (*Store) NextBLeg

func (s *Store) NextBLeg(ctx context.Context, aLegID string) (b2bua.BLegRecord, error)

func (*Store) RecordAttempt

func (s *Store) RecordAttempt(ctx context.Context, rec lipapi.AttemptRecord) error

func (*Store) Replace

func (s *Store) Replace(ctx context.Context, aLegID, selector string, now time.Time) (routeoverride.State, error)

Replace activates or replaces the A-leg override selector.

func (*Store) ResolveALeg

func (s *Store) ResolveALeg(ctx context.Context, continuityKey string) (b2bua.ALegRecord, error)

func (*Store) SetALegRetirementObserver

func (s *Store) SetALegRetirementObserver(observer func(string))

SetALegRetirementObserver binds the process-owned session retirement callback.

func (*Store) SetInterleavedRow

func (s *Store) SetInterleavedRow(ctx context.Context, aLegID string, dto LegacyInterleavedStateRowDTO) error

SetInterleavedRow persists the compatibility DTO containing both core cycle state and legacy memo_ref payload for an A-leg, preserving durable backward compatibility.

func (*Store) SetInterleavedState

func (s *Store) SetInterleavedState(ctx context.Context, aLegID string, state interleavedstate.State) error

SetInterleavedState persists the thinker cycle state for an A-leg, preserving any existing legacy memo reference through a read-modify-write merge. An empty cycle state with no existing memo reference clears the stored state (stored as the zero-value empty string). Invalid state is rejected without mutating the stored value.

func (*Store) SetWeightedFirstConsumed

func (s *Store) SetWeightedFirstConsumed(ctx context.Context, aLegID string, consumed bool) error

func (*Store) Snapshot

func (s *Store) Snapshot(ctx context.Context, aLegID string) (routeoverride.State, error)

Snapshot returns a complete value copy of the A-leg override state.

Jump to

Keyboard shortcuts

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