Skip to content

Module github.com/bide-ai/bide/store/sqlite ​

Go module github.com/bide-ai/bide/store/sqlite; all modules.

store/sqlite ​

github.com/bide-ai/bide/store/sqlite · pkg.go.dev · Stability: core

Package sqlite is the default on-disk agent.Store: a single-file, zero-cgo SQLite journal (via modernc.org/sqlite).

type EventStore ​

go
type EventStore struct {
	// contains filtered or unexported fields
}

EventStore is a SQLite-backed audit.EventStore: the durable copy of a run's event trail (see audit.PersistJournal and audit.LoadEventLog), in the file's bide_events table (see WithTablePrefix).

Methods

  • func (e *EventStore) Append(ctx context.Context, runID string, seq int, leaf []byte) error: Append implements audit.EventStore.
  • func (e *EventStore) Load(ctx context.Context, runID string) ([][]byte, error): Load implements audit.EventStore.

type Option ​

go
type Option interface {
	// contains filtered or unexported methods
}

Option configures Open and New.

Constructors and functions

  • func WithTablePrefix(prefix string) Option: WithTablePrefix names the tables with prefix instead of "bide_": prefix+"steps", prefix+"leases", prefix+"events" and prefix+"schema_version".

type Store ​

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

Store is a SQLite-backed agent.Store.

Constructors and functions

  • func New(ctx context.Context, db *sql.DB, opts ...Option) (*Store, error): New returns a Store over db, which the caller opened and closes.
  • func Open(path string, opts ...Option) (*Store, error): Open opens (creating if needed) a SQLite journal at path, in WAL mode, with its three connection pools.
  • func OpenReadOnly(path string, opts ...Option) (*Store, error): OpenReadOnly opens the SQLite journal at path for reading only.

Methods

  • func (s *Store) AcquireLease(ctx context.Context, runID, holder string, ttl time.Duration) (bool, error): AcquireLease implements agent.Leaser with one upsert: it grants the lease when the run is unleased, already held by holder (a renewal), or the current lease has expired.
  • func (s *Store) Close() error: Close closes the connection pools Open opened.
  • func (s *Store) Compact(ctx context.Context) (agent.CompactionReport, error): Compact implements agent.Compactor: it checkpoints the write-ahead log and truncates it (PRAGMA wal_checkpoint(TRUNCATE)), which copies the pages an erasure rewrote (their old bytes zeroed, see Redact) into the database file and empties the log that held the old pages.
  • func (s *Store) EventStore() *EventStore: EventStore returns the audit.EventStore over s's database.
  • func (s *Store) Get(ctx context.Context, runID, name string) (agent.Entry, bool, error): Get implements agent.Store.
  • func (s *Store) Holds(ctx context.Context) ([]agent.Hold, error): Holds implements agent.Holder.
  • func (s *Store) Insert(ctx context.Context, runID, name string, data []byte) (agent.Entry, bool, error): Insert implements agent.Store.
  • func (s *Store) LiftHold(ctx context.Context, id string) (bool, error): LiftHold implements agent.Holder.
  • func (s *Store) Load(ctx context.Context, runID string, after int64) iter.Seq2[agent.Entry, error]: Load implements agent.Store.
  • func (s *Store) PlaceHold(ctx context.Context, h agent.Hold) error: PlaceHold implements agent.Holder: one statement, so atomic, that inserts a row for each run the hold names; a hold whose ID is active already violates the key and is refused.
  • func (s *Store) ReapLeases(ctx context.Context, ended []string) (int, error): ReapLeases implements agent.Leaser with one DELETE, which checks the expiry in the same statement, so a lease taken or renewed meanwhile is kept.
  • func (s *Store) Redact(ctx context.Context, runID, name string, current, tombstone []byte) (bool, error): Redact implements agent.Redactor with one UPDATE that replaces the entry only if it holds current, the run holds an end marker and no lease on the run is live (see agent.Redactor).
  • func (s *Store) ReleaseLease(ctx context.Context, runID, holder string) error: ReleaseLease implements agent.Leaser: it deletes runID's lease if holder holds it.
  • func (s *Store) RenewLease(ctx context.Context, runID, holder string, ttl time.Duration) (bool, error): RenewLease implements agent.Leaser: it extends holder's still-live lease on runID.
  • func (s *Store) Runs(ctx context.Context, f agent.RunFilter) iter.Seq2[string, error]: Runs implements agent.Lister.

Apache-2.0 licensed.