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
- func DecodeInterleavedStateRow(encoded string) (interleavedstate.State, json.RawMessage, error)
- func EncodeInterleavedStateRow(dto LegacyInterleavedStateRowDTO) (string, error)
- func RunSchemaMigrate(ctx context.Context, db *bun.DB) error
- type LegacyInterleavedStateRowDTO
- type Store
- func (s *Store) Clear(ctx context.Context, aLegID string, now time.Time) (routeoverride.State, error)
- func (s *Store) Close() error
- func (s *Store) CreateALeg(ctx context.Context, continuityKey string) (b2bua.ALegRecord, error)
- func (s *Store) DB() *bun.DB
- func (s *Store) FetchALeg(ctx context.Context, aLegID string) (b2bua.ALegRecord, error)
- func (s *Store) FetchInterleavedRow(ctx context.Context, aLegID string) (LegacyInterleavedStateRowDTO, error)
- func (s *Store) FetchInterleavedState(ctx context.Context, aLegID string) (interleavedstate.State, error)
- func (s *Store) FetchInterleavedStateRow(ctx context.Context, aLegID string) (interleavedstate.State, json.RawMessage, error)
- func (s *Store) Get(ctx context.Context, aLegID string) (routeoverride.State, error)
- func (s *Store) LoadAttempts(ctx context.Context, aLegID string) (out []lipapi.AttemptRecord, err error)
- func (s *Store) NextBLeg(ctx context.Context, aLegID string) (b2bua.BLegRecord, error)
- func (s *Store) RecordAttempt(ctx context.Context, rec lipapi.AttemptRecord) error
- func (s *Store) Replace(ctx context.Context, aLegID, selector string, now time.Time) (routeoverride.State, error)
- func (s *Store) ResolveALeg(ctx context.Context, continuityKey string) (b2bua.ALegRecord, error)
- func (s *Store) SetALegRetirementObserver(observer func(string))
- func (s *Store) SetInterleavedRow(ctx context.Context, aLegID string, dto LegacyInterleavedStateRowDTO) error
- func (s *Store) SetInterleavedState(ctx context.Context, aLegID string, state interleavedstate.State) error
- func (s *Store) SetWeightedFirstConsumed(ctx context.Context, aLegID string, consumed bool) error
- func (s *Store) Snapshot(ctx context.Context, aLegID string) (routeoverride.State, error)
Constants ¶
const BaselineMigrationName = "20250426000000"
BaselineMigrationName is the name bun/migrate records for this adapter's baseline (file prefix).
const ConversationViewMigrationName = "20260814000000"
ConversationViewMigrationName is the bun/migrate name for the conversation-view tables (file prefix).
const InterleavedStateMigrationName = "20250427000000"
InterleavedStateMigrationName is the bun/migrate name for the interleaved thinking state column addition (file prefix).
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.
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 ¶
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 ¶
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) CreateALeg ¶
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) LoadAttempts ¶
func (*Store) RecordAttempt ¶
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 (*Store) SetALegRetirementObserver ¶
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.