sqlite

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 69 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 sqlite is the loop's one store: a SQLite database with one versioned schema that every repository shares.

Index

Constants

View Source
const (
	SessionEventsKey = "session_events"
	ViewEventsKey    = "view_events"
)

The Retained keys of the events SessionEvents and ViewEvents drop.

View Source
const (
	WorkflowEventsKey   = "workflow_events"
	UnitlessLoopRowsKey = "unitless_loop_rows"
)

The Retained keys of WorkflowEvents and UnitlessLoopRows; WorkflowRuns and PlanItems count under their tables.

View Source
const (
	KindPaused  = "paused"
	KindResumed = "resumed"
)

The kinds of the event a pause or a resume leaves.

View Source
const DefaultKeep = 3

DefaultKeep is how many pre-migration backups stay.

View Source
const DefaultWarmFor = 72 * time.Hour

DefaultWarmFor is items.heat.warm_for when unset.

View Source
const PreRestoreDays = 30

PreRestoreDays is how long the copies Restore keeps of a replaced store stay.

View Source
const ReadConns = 4

ReadConns is the size of the read pool.

View Source
const SchemaVersion = 15

SchemaVersion is the PRAGMA user_version of a store this release creates and migrates to.

View Source
const TimeLayout = time.RFC3339Nano

Variables

View Source
var DefaultRetention = Retention{
	SessionEvents:    retentionWindow,
	ViewEvents:       retentionWindow,
	ClosedSessions:   retentionWindow,
	Stops:            turns.StopsKept,
	Instructions:     retentionWindow,
	BriefBodies:      7 * 24 * time.Hour,
	EndedPRs:         400 * 24 * time.Hour,
	WorkflowRuns:     retentionWindow,
	PlanItems:        7 * 24 * time.Hour,
	WorkflowEvents:   retentionWindow,
	UnitlessLoopRows: retentionWindow,
	Classifications:  retentionWindow,
	Fetches:          retentionWindow,
	SubjectMarks:     true,
	VacuumPages:      4096,
}

DefaultRetention is what the daemon's retain job applies. ViewRows stays zero: the views re-plan a unit whose applied rows are gone, and every ended unit with a turn book is still planned.

View Source
var ErrDamaged = errors.New("the store is damaged")

ErrDamaged is a store that fails SQLite's integrity checks.

View Source
var ErrNoSpace = errors.New("not enough free space for the store's backup")

ErrNoSpace is too little free space for the backup a migration takes.

View Source
var ErrSchema = errors.New("the store is not at this release's schema version")
View Source
var ErrStoreBusy = errors.New("another process has the store open")

ErrStoreBusy is a store whose lock another process holds.

SessionEventKinds are the bookkeeping kinds SessionEvents drops. Pause events and every event of a pull request are kept.

Functions

func AdoptJobDrafts added in v0.2.0

func AdoptJobDrafts(ctx context.Context, tx *sql.Tx) error

AdoptJobDrafts rewrites every draft the proposals job proposed under its rules, in any state, to the identity of the default workflow that replaced the rule: rule and workflow stalled-nudge to slack-stalled-nudge, closure to slack-closure, ask-owner to slack-ask-owner, rule_key unchanged, so the workflow's hold and withdrawal see them; a draft not sent gets the workflow's effects.

func Check

func Check(path string) error

Check refuses a store at path that this release cannot open as it is, reading its file without opening it for writing. An absent or empty file passes: Open creates it.

func LockStore added in v0.2.0

func LockStore(path string) (unlock func(), err error)

LockStore takes, without waiting, the lock of the store at path that its writer holds: the daemon while it serves, and a command that migrates or restores the store. A held lock is ErrStoreBusy.

func Megabytes added in v0.2.0

func Megabytes(n int64) string

Megabytes is n bytes as whole megabytes, rounded up.

func ParseKey

func ParseKey(key string) (pr.Ref, error)

ParseKey reads the owner/repo#n key of the round state.

func Refuse added in v0.2.0

func Refuse(path string, s Status) error

Refuse is the SchemaError of a store in s at path, nil when this release opens it.

func StoredUnit

func StoredUnit(u unit.Unit, kind, key string) unit.Unit

StoredUnit is the unit an event of u, kind and key is stored under: u, or the session unit of the key's handle for a handle-keyed kind with no unit. Every writer of events applies it.

func UnitPairs added in v0.4.0

func UnitPairs(units []unit.Unit) (string, error)

UnitPairs are units as the JSON list of [provider, key] a query reads with json_each.

Types

type AgentSession

type AgentSession struct {
	ID, Kind, Handle, Home, Worktree, Transcript string
	FirstSeen, LastSeen                          time.Time
}

AgentSession is what the hooks told of one agent session; a resume keeps the handle and starts another.

type AgentWorktree

type AgentWorktree struct{ Home, Worktree string }

AgentWorktree is a worktree an agent session of the loop ran in, with the agent's home.

type Backup added in v0.2.0

type Backup struct {
	Path    string
	Version uint32
	Taken   time.Time
	// PreRestore is the store as it was before a restore replaced it.
	PreRestore bool
	Size       int64
	// contains filtered or unexported fields
}

Backup is a copy of the store in the backups directory.

func Backups added in v0.2.0

func Backups(dir string) ([]Backup, error)

Backups lists the backups in dir, newest first; an absent dir has none.

func Restorable added in v0.2.0

func Restorable(all []Backup) (Backup, bool)

Restorable is the newest backup in all, newest first as Backups lists them, that this release opens or migrates; pre-restore copies are left for an explicit choice.

type Classifications

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

Classifications caches classify outputs by unit, workflow and the unit's fingerprint, and counts the calls of each local day for the daily cap. Its writes note nothing.

func (*Classifications) Output

func (c *Classifications) Output(ctx context.Context, u unit.Unit, workflow, fingerprint string) (json.RawMessage, bool, error)

Output is the stored output of workflow for u at fingerprint.

func (*Classifications) Save

func (c *Classifications) Save(ctx context.Context, u unit.Unit, workflow, fingerprint string, output json.RawMessage, at time.Time) error

Save stores output, a JSON value, replacing the one stored for the same unit, workflow and fingerprint.

func (*Classifications) Spend

func (c *Classifications) Spend(ctx context.Context, at time.Time, limit int) (bool, error)

Spend counts one classify call on the day of at in at's location when fewer than limit are counted there, and says whether it did.

func (*Classifications) Spent

func (c *Classifications) Spent(ctx context.Context, at time.Time) (int, error)

Spent is how many calls Spend counted on the day of at in at's location.

type DB

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

DB is the store: one writer connection, reached only through Write, and a read-only pool of ReadConns connections.

func Open

func Open(path string, log Noter) (*DB, error)

Open opens the store at path, creating it at SchemaVersion when it holds no table, and refuses with a SchemaError a store it cannot open as it is: an older one, which Migrate takes first, or a newer one that is not compatible. Both handles open through connector. A nil log gets a private change log.

func OpenReadOnly

func OpenReadOnly(path string) (*DB, error)

OpenReadOnly opens the store at path for reads only, for a process that is not the store's writer; it creates nothing and refuses a store at another version.

func (*DB) Activities added in v0.2.0

func (db *DB) Activities(ctx context.Context, provider unit.ProviderID) (map[unit.Unit]turn.Activity, error)

Activities reads the activity of every unit of provider that has any, in one statement: one aggregated part per table.

func (*DB) AgentTranscript

func (db *DB) AgentTranscript(ctx context.Context, agentSession string) (path, kind string, err error)

AgentTranscript is the transcript file and agent the hooks stored for the agent session, "" for each when none is stored.

func (*DB) AgentWorktrees

func (db *DB) AgentWorktrees(ctx context.Context) ([]AgentWorktree, error)

AgentWorktrees lists the distinct worktrees the loop's sessions ran in.

func (*DB) AllSkips added in v0.4.0

func (db *DB) AllSkips(ctx context.Context) (map[unit.Unit][]string, error)

AllSkips are the skipped workflows by unit, each unit's sorted by name.

func (*DB) AutomatedTurns added in v0.2.0

func (db *DB) AutomatedTurns(ctx context.Context, from time.Time, except []unit.ProviderID) (int, error)

AutomatedTurns counts the automated turns sent since from on units of providers other than except's, withdrawn ones included: a turn a workflow started spends the day's budget whatever became of it.

func (*DB) CallSpent added in v0.4.0

func (db *DB) CallSpent(ctx context.Context, from, to time.Time, kinds ...string) (float64, error)

CallSpent is the cost of the calls recorded in [from, to) as events of kinds, whose Data is the cost.

func (*DB) Cards

func (db *DB) Cards() card.Store

Cards is the store of the units' card snapshots.

func (*DB) Classifications

func (db *DB) Classifications() *Classifications

func (*DB) Close

func (db *DB) Close() error

Close closes both handles and waits, up to closeWait, for the statements in flight to release their connections, so the store's files stop changing once it returns. Connections still open then are an error.

func (*DB) DeleteSkip added in v0.4.0

func (db *DB) DeleteSkip(ctx context.Context, workflow string, u unit.Unit) error

DeleteSkip forgets that workflow is skipped on u; deleting none is no error.

func (*DB) DraftEffects added in v0.2.0

func (db *DB) DraftEffects() outbox.AppliedStore

DraftEffects keeps when the effects of a sent draft were applied.

func (*DB) Drafts

func (db *DB) Drafts() outbox.Store

Drafts is the Outbox's store.

func (*DB) Events

func (db *DB) Events() automation.Events

Events reads the events table by id for event workflows, and keeps each workflow's cursor and last firing. Advancing a cursor notes nothing.

func (*DB) EventsOf added in v0.3.0

func (db *DB) EventsOf(ctx context.Context, units []unit.Unit, f timeline.Filter) ([]timeline.Event, error)

EventsOf are the events of units f keeps, newest first by their row id.

func (*DB) EventsOfKinds added in v0.4.0

func (db *DB) EventsOfKinds(ctx context.Context, kinds []string) ([]workflow.Event, error)

EventsOfKinds are every unit's events of kinds, oldest first, as Events().Since reads them.

func (*DB) Fetches

func (db *DB) Fetches() *Fetches

func (*DB) Gates added in v0.3.0

func (db *DB) Gates(now func() time.Time) GateStore

Gates is the store of the gates.

func (*DB) HeadlessSpent

func (db *DB) HeadlessSpent(ctx context.Context, from, to time.Time) (float64, error)

HeadlessSpent is the cost in turn_usage of the headless turns started in [from, to).

func (*DB) Held added in v0.3.0

func (db *DB) Held(ctx context.Context, p unit.ProviderID) ([]unit.Unit, error)

Held are the units of provider p the user holds.

func (*DB) Intakes

func (db *DB) Intakes() intake.Store

func (*DB) Items

func (db *DB) Items() coreitems.Store

Items is the items ledger's store: items, their op log and proposals.

func (*DB) ItemsHeld added in v0.3.0

func (db *DB) ItemsHeld(ctx context.Context, u unit.Unit) (map[task.ID][]string, error)

ItemsHeld are the items of u each task holding u or one of its items holds; a task that holds u and none of its items maps to none.

func (*DB) Ledger

func (db *DB) Ledger() automation.Ledger

Ledger is the workflows' plan and runs. A write stores its rows and its events in one transaction, noting TopicLoopEvents for the events and TopicPending only when the pending set changes and TopicPlan only when what the plan serves of an item changes.

func (*DB) LinkTargets

func (db *DB) LinkTargets(ctx context.Context) ([]unit.Unit, error)

LinkTargets are the units some link that can resolve an item points to, sorted by provider and key.

func (db *DB) Links() port.LinkStore

Links is the store of cross-source links.

func (*DB) LinksFrom added in v0.4.0

func (db *DB) LinksFrom(ctx context.Context, units []unit.Unit) ([]link.Link, error)

LinksFrom are the links from any of units, sorted by From, then At.

func (*DB) Marks added in v0.2.0

func (db *DB) Marks(ctx context.Context, u unit.Unit) (map[string]string, error)

Marks are u's handled marks by name.

func (*DB) MergedInto added in v0.4.0

func (db *DB) MergedInto(ctx context.Context, id task.ID) ([]task.ID, error)

MergedInto are the tasks merged into task id, transitively, in merge order: the old ids of the aliases that lead to id, hop by hop, that no stored task holds and whose newest merge record names the alias's new id.

func (*DB) Override added in v0.3.0

func (db *DB) Override(ctx context.Context, u unit.Unit) (map[string]string, error)

Override is u's host overrides by name, the unset ones absent.

func (*DB) Projects

func (db *DB) Projects() coretasks.ProjectStore

Projects are the Review's runs; a project's own fields are read and written with its task.

func (*DB) Props added in v0.3.0

func (db *DB) Props(now func() time.Time) PropStore

Props is the store of the tasks' properties.

func (*DB) PutRecord added in v0.3.0

func (db *DB) PutRecord(ctx context.Context, u unit.Unit, kind string, w task.Writer, data []byte, at time.Time) error

PutRecord keeps data as u's record of kind, written by w at at, in place of the one it kept: the new record takes the newest Seq.

func (*DB) PutUnitBrief added in v0.3.0

func (db *DB) PutUnitBrief(ctx context.Context, u unit.Unit, version, body string, at time.Time) error

PutUnitBrief keeps body, a brief's JSON a source plugin wrote of u at version, as the brief u uses: u's brief record, and u's plugin run of at's day, updated in place, or a new ok run.

func (*DB) R

func (db *DB) R() Reader

R is the read pool, for a read of one statement. Under a Snapshot's ctx it reads in that snapshot's transaction.

func (*DB) Read

func (db *DB) Read(ctx context.Context, fn func(tx *sql.Tx) error) error

Read runs fn in one deferred read transaction on the pool, so every statement sees one snapshot; under a Snapshot's ctx it runs in that snapshot's transaction. fn must not write.

func (*DB) Records added in v0.3.0

func (db *DB) Records(ctx context.Context, kind string, units ...unit.Unit) (map[unit.Unit]port.Event, error)

Records are the record of kind each of units keeps; with no units, every unit's.

func (*DB) RehomeDrafts added in v0.3.0

func (db *DB) RehomeDrafts(ctx context.Context, moves map[unit.Unit]unit.Unit) (int, error)

RehomeDrafts moves the drafts of each unit of moves onto the unit it maps to, in one transaction, and counts them; a second call moves none.

func (*DB) Retain

func (db *DB) Retain(ctx context.Context, now time.Time, p Retention) (Retained, error)

Retain applies p as of now in one write transaction, noting Change.All with the topics of the tables it changed, then runs incremental_vacuum and PRAGMA optimize outside it. EndedPRs runs first, so the rules after it see the sessions and runs only an ended pull request's turns held, and a second pass at the same now changes nothing and notes nothing.

func (*DB) SaveAgentSession

func (db *DB) SaveAgentSession(ctx context.Context, a AgentSession) error

SaveAgentSession upserts a; an empty field never clears a stored one, and the seen times only widen.

func (*DB) SaveSkip added in v0.4.0

func (db *DB) SaveSkip(ctx context.Context, workflow string, u unit.Unit, at time.Time) error

SaveSkip keeps that workflow is skipped on u; saving it again keeps the first time.

func (*DB) SetMarks added in v0.3.0

func (db *DB) SetMarks(ctx context.Context, u unit.Unit, marks map[string]string) error

SetMarks sets u's marks by name in one transaction; a value "" removes one.

func (*DB) SetOverride added in v0.3.0

func (db *DB) SetOverride(ctx context.Context, u unit.Unit, set, ifMatch map[string]string) (written bool, err error)

SetOverride sets u's host overrides of set, in one transaction, only while each of ifMatch holds its value ("" for unset); a value "" clears one. Written is false when ifMatch did not hold.

func (*DB) Snapshot

func (db *DB) Snapshot(ctx context.Context, fn func(ctx context.Context) error) error

Snapshot pins one deferred read transaction to the returned ctx: every store read made with it inside fn, in sqlite and inventory, uses that transaction, so a multi-method load sees one commit.

func (*DB) Snapshots added in v0.3.0

func (db *DB) Snapshots() snapshot.Store

Snapshots is the store of the units' reported snapshots.

func (*DB) Tasks added in v0.3.0

func (db *DB) Tasks() coretasks.Store

func (*DB) TasksHolding added in v0.3.0

func (db *DB) TasksHolding(ctx context.Context, u unit.Unit) ([]task.ID, error)

TasksHolding are the tasks that hold u, oldest first.

func (*DB) TasksRunByHand added in v0.4.0

func (db *DB) TasksRunByHand(ctx context.Context, kinds []string, ids ...task.ID) (map[task.ID]bool, error)

TasksRunByHand are, of ids, or of every task when ids is empty, the tasks on whose own unit an event of one of kinds was recorded by a person or an agent.

func (*DB) UnitEventKeys

func (db *DB) UnitEventKeys(ctx context.Context, u unit.Unit, kind string) (map[string]time.Time, error)

UnitEventKeys maps the keys of u's events of kind to when each was recorded.

func (*DB) UnitsOf added in v0.3.0

func (db *DB) UnitsOf(ctx context.Context, id task.ID) ([]unit.Unit, error)

UnitsOf are the units task id holds, in its order, then the own unit of every task merged into id, in merge order.

func (*DB) Usage

func (db *DB) Usage() usage.Store

func (*DB) Wakes added in v0.3.0

func (db *DB) Wakes() WakeStore

Wakes is the store of the tasks' wakes.

func (*DB) WorkflowActivity

func (db *DB) WorkflowActivity(ctx context.Context, since time.Time) (map[string]WorkflowActivity, error)

WorkflowActivity is each workflow's newest done run and its step refusals since since, by workflow name.

func (*DB) Worktrees

func (db *DB) Worktrees() Worktrees

func (*DB) Write

func (db *DB) Write(ctx context.Context, fn func(tx *Tx) error) (port.Change, error)

Write runs fn in one write transaction under the store file's write lock, which every handle this process has open on it shares. After COMMIT, when fn touched anything, it notes the log (still under the lock, so log order is commit order) and returns that Change; otherwise the zero Change. An error from fn rolls back and notes nothing. A nested Write panics.

type Fetches

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

Fetches is when each workspace was last fetched. Its writes note nothing.

func (*Fetches) Last

func (f *Fetches) Last(ctx context.Context, id string) (time.Time, error)

Last is the last fetch of workspace id, zero when it was never fetched.

func (*Fetches) Mark

func (f *Fetches) Mark(ctx context.Context, id string, at time.Time) error

type GateStore added in v0.3.0

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

GateStore is the gates; now stamps OpenedAt and ClosedAt.

func (GateStore) Applied added in v0.3.0

func (s GateStore) Applied(ctx context.Context, id int64) error

Applied marks resolved gate id's consequence as run.

func (GateStore) Begin added in v0.3.0

func (s GateStore) Begin(ctx context.Context, id int64) error

Begin marks resolved gate id's consequence run, and begun until End.

func (GateStore) Begun added in v0.3.0

func (s GateStore) Begun(ctx context.Context) ([]gate.Gate, error)

Begun are the resolved gates whose consequence began and never ended.

func (GateStore) Due added in v0.3.0

func (s GateStore) Due(ctx context.Context, now time.Time) ([]gate.Gate, error)

Due are the open gates whose Deadline is set and not after now.

func (GateStore) End added in v0.3.0

func (s GateStore) End(ctx context.Context, id int64) error

End marks gate id's begun consequence ended.

func (GateStore) Get added in v0.3.0

func (s GateStore) Get(ctx context.Context, id int64) (gate.Gate, error)

Get is gate id.

func (GateStore) OfTask added in v0.3.0

func (s GateStore) OfTask(ctx context.Context, id task.ID) ([]gate.Gate, error)

OfTask are task id's gates, open and closed.

func (GateStore) Open added in v0.3.0

func (s GateStore) Open(ctx context.Context, g gate.Gate) (gate.Gate, error)

Open stores g as open with a new ID and OpenedAt.

func (GateStore) Resolve added in v0.3.0

func (s GateStore) Resolve(ctx context.Context, id int64, r gates.Resolution) (gate.Gate, error)

Resolve closes the open gate id with r.

func (GateStore) Unapplied added in v0.3.0

func (s GateStore) Unapplied(ctx context.Context) ([]gate.Gate, error)

Unapplied are the resolved gates whose consequence has not run.

func (GateStore) Where added in v0.3.0

func (s GateStore) Where(ctx context.Context, q gates.Query) ([]gate.Gate, error)

Where are the gates matching q.

type HeatReader

type HeatReader struct {
	DB      *DB
	WarmFor func() time.Duration // nil or zero: DefaultWarmFor
	Clock   port.Clock
}

HeatReader reads port.Heat from the items ledger: active while a unit has an open item, warm for WarmFor after its last item resolved, cold otherwise.

func (HeatReader) Heat

func (h HeatReader) Heat(ctx context.Context, units []unit.Unit) (map[unit.Unit]port.Heat, error)

type MigrateOptions added in v0.2.0

type MigrateOptions struct {
	Backups string
	Now     func() time.Time
	// Keep is how many backups taken before a migration stay; 0 keeps
	// DefaultKeep.
	Keep int
	// Backup, when set, is the backup's path, as a Plan named it.
	Backup string
	// BackedUp, when set, runs once the store's backup is written, before
	// any migration; its error stops Migrate with the store unchanged.
	BackedUp func(backup string) error
	// Step, when set, hears of each migration as it commits.
	Step func(label string, took time.Duration)
	// Warn, when set, hears of what failed after the migrations committed
	// without undoing them, such as removing an old backup.
	Warn func(error)
}

MigrateOptions are where Migrate keeps backups and what it reports.

type MigrationError added in v0.2.0

type MigrationError struct {
	From, Reached uint32
	Step          string
	Backup        string
	Err           error
}

MigrationError is a migration that failed; the store stays at Reached.

func (*MigrationError) Error added in v0.2.0

func (e *MigrationError) Error() string

func (*MigrationError) Unwrap added in v0.2.0

func (e *MigrationError) Unwrap() error

type Noter

type Noter interface {
	Note(t port.Topic, units ...unit.Unit) port.Change
	NoteAll(t port.Topic) port.Change
}

Noter is what Write notes into; *change.Log satisfies it.

type Plan added in v0.2.0

type Plan struct {
	From, To uint32
	// Steps are the migrations it runs, as 0002_name.
	Steps []string
	// Backup is the file it copies the store to first.
	Backup string
	// Size is the store's size with its WAL, and Free the bytes free where
	// the backup goes, -1 when unknown.
	Size, Free int64
	// Compatible is the oldest version a release must be at to read the store once migrated.
	Compatible uint32
}

Plan is what Migrate does to a store.

func Migrate added in v0.2.0

func Migrate(ctx context.Context, path string, o MigrateOptions) (Plan, error)

Migrate takes the store at path to SchemaVersion: it checks the store, copies it into o.Backups, runs each pending migration in its own transaction, checks the result and prunes old backups. The caller holds the store's lock (LockStore). A store with nothing pending is left alone.

func PlanMigration added in v0.2.0

func PlanMigration(path, backups string, now time.Time) (Plan, error)

PlanMigration is what Migrate would do to the store at path, with its backup in the directory backups; it changes nothing. A store this release cannot migrate is a SchemaError.

func (Plan) Pending added in v0.2.0

func (p Plan) Pending() bool

Pending says the plan migrates anything.

func (Plan) ReadableAfter added in v0.4.0

func (p Plan) ReadableAfter() bool

ReadableAfter says a release at the store's version now still reads it once migrated.

func (Plan) Short added in v0.2.0

func (p Plan) Short() bool

Short says the free space cannot hold the backup with room to spare.

type PropStore added in v0.3.0

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

PropStore is the tasks' properties; now stamps each write.

func (PropStore) PropsOf added in v0.3.0

func (s PropStore) PropsOf(ctx context.Context, id task.ID) (task.Props, error)

func (PropStore) SetProp added in v0.3.0

func (s PropStore) SetProp(ctx context.Context, id task.ID, name string, v task.Value, w task.Writer) error

SetProp writes the property, or deletes it for a zero v, and moves the task to a new rev, so a page since an older one lists it again; a write that changes neither value nor writer moves nothing.

type Reader

type Reader interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Reader is what a single read statement needs. An Exec through the pool fails with SQLITE_READONLY.

type Restored added in v0.2.0

type Restored struct {
	From Status
	// Kept is the copy of the store Restore replaced; empty when there was
	// none.
	Kept string
}

Restored is what Restore did.

func Restore added in v0.2.0

func Restore(ctx context.Context, path, from, backups string, now time.Time) (Restored, error)

Restore replaces the store at path with the backup at from, after copying the store into the backups directory as a pre-restore copy. The caller holds the store's lock. A backup older than SchemaVersion stays older: Migrate takes it forward.

type Retained

type Retained map[string]int

Retained counts the rows a pass deleted or compacted, per table; the events SessionEvents and ViewEvents drop count under their own keys, and "events" counts those of ended pull requests.

func (Retained) String

func (r Retained) String() string

String lists the tables a pass changed, in name order: "events 3, sessions 1", or "nothing".

type Retention

type Retention struct {
	SessionEvents time.Duration // events of no unit or a session unit, of the kinds in SessionEventKinds
	ViewEvents    time.Duration // view_applied, view_override and view_sink_failed events
	// ClosedSessions drops the sessions closed that long ago that no open
	// turn names, and the agent sessions last seen that long ago whose turns
	// all have their usage read.
	// It also drops the workflow runs of session units that old whose
	// session row is gone.
	ClosedSessions time.Duration
	Stops          time.Duration // turn_stops
	Instructions   time.Duration // turn_instructions, then the parts no row lists
	// BriefBodies empties brief and input of the runs started that long ago
	// that no unit_briefs row or turn references.
	BriefBodies time.Duration
	ViewRows    time.Duration // view_applied rows of pull requests merged or closed that long ago
	EndedPRs    time.Duration // a pull request merged or closed that long ago, with every row of it
	// WorkflowRuns drops the done workflow runs that old. A dismissed run
	// keeps its key terminal, so it goes only with its unit's rows.
	WorkflowRuns   time.Duration
	PlanItems      time.Duration // plan items not pending, last saved that long ago
	WorkflowEvents time.Duration // the engine's events, workflow.EngineKinds
	// UnitlessLoopRows drops the turns, records, answers, intakes, events,
	// workflow runs and plan items of a github unit the GitHub plugin does
	// not report, with no overrides row and nothing newer.
	UnitlessLoopRows time.Duration
	Classifications  time.Duration // classifications and classify_days
	Fetches          time.Duration
	// SubjectMarks drops the marks of tasks done, in the trash or gone,
	// and of Slack units the Slack plugin does not report, with no item and
	// no task.
	SubjectMarks bool
	VacuumPages  int // PRAGMA incremental_vacuum(VacuumPages) after each pass; 0 runs none
}

Retention says how long each kind of row is kept. Zero keeps forever. Every event, turn, record, answer, plan item and brief of a task, or of a unit linked to a task, is kept forever: no rule reaches them.

type Rounds

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

Rounds is the round state's repository.

func NewRounds

func NewRounds(db *DB) *Rounds

func (*Rounds) AgentHome

func (r *Rounds) AgentHome(ctx context.Context, ref pr.Ref) (string, error)

AgentHome is the agent home remembered for the pull request's rounds, empty when none is.

func (*Rounds) Load

func (r *Rounds) Load(ctx context.Context) (*round.Store, error)

func (*Rounds) Pause

func (r *Rounds) Pause(ctx context.Context) (round.Pause, error)

func (*Rounds) Save

func (r *Rounds) Save(ctx context.Context, st *round.Store) error

Save writes only the fields st's setters changed, adds its rounds to the day's counters and drops the days before the newest one it counts.

func (*Rounds) SetPause

func (r *Rounds) SetPause(ctx context.Context, p round.Pause) error

SetPause writes the row and a paused or resumed event in one transaction.

type SchemaError added in v0.2.0

type SchemaError struct {
	Path   string
	Status Status
	// contains filtered or unexported fields
}

SchemaError is a store at a version this release cannot open as it is.

func (SchemaError) Error added in v0.2.0

func (e SchemaError) Error() string

func (SchemaError) Is added in v0.2.0

func (e SchemaError) Is(target error) bool

func (SchemaError) State added in v0.2.0

func (e SchemaError) State() State

type State added in v0.2.0

type State int

State is how a store's version stands against this release.

const (
	// StateCurrent is a store at SchemaVersion, or no store yet.
	StateCurrent State = iota
	// StateOlder is a store Migrate takes to SchemaVersion.
	StateOlder
	// StateReadable is a newer store whose changes this release can still use.
	StateReadable
	// StateNewer is a newer store this release must not open.
	StateNewer
	// StateUnknown is a store at no version a release writes.
	StateUnknown
)

type Status added in v0.2.0

type Status struct {
	Version uint32
	// Compatible is the lowest version a release must read to use the store.
	Compatible uint32
	// Empty is an absent store, or one with no table yet.
	Empty bool
}

Status is a store's schema version as read from its file.

func Inspect added in v0.2.0

func Inspect(path string) (Status, error)

Inspect reads the schema version of the store at path from its header; for a store newer than this release it also reads the compatible version, opening the store for reads.

func (Status) Opens added in v0.2.0

func (s Status) Opens() bool

Opens says this release opens a store in s without migrating it.

func (Status) State added in v0.2.0

func (s Status) State() State

State places s against this release.

type Store

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

Store is the repository of the turns, the sessions and what the views applied. Every save writes its events in its own transaction.

func New

func New(db *DB) *Store

func (*Store) Applied

func (s *Store) Applied(ctx context.Context, sink string) (map[view.Key]view.Applied, error)

func (*Store) BindHandle

func (s *Store) BindHandle(ctx context.Context, id, manager, handle, runtime string, at time.Time) error

BindHandle makes handle the session's open handle from at, ending the one before; binding the open handle again changes nothing.

func (*Store) BookOf

func (s *Store) BookOf(ctx context.Context, k turns.Key) (turn.Book, bool, error)

func (*Store) Books

func (s *Store) Books(ctx context.Context, units ...unit.Unit) (map[unit.Unit]turn.Book, error)

func (*Store) EndHandle

func (s *Store) EndHandle(ctx context.Context, id string, at time.Time) error

EndHandle ends the session's open handle at at: the session is dormant.

func (*Store) LastStops

func (s *Store) LastStops(ctx context.Context, sessions []string) (map[string]turn.Stop, error)

LastStops returns the newest stop of each session that logged one.

func (*Store) LogStop

func (s *Store) LogStop(ctx context.Context, st turn.Stop, evs ...port.Event) error

func (*Store) Open

func (s *Store) Open(ctx context.Context) ([]unit.Unit, error)

func (*Store) OpenTurns added in v0.4.0

func (s *Store) OpenTurns(ctx context.Context) (map[unit.Unit][]turn.Turn, error)

OpenTurns are the open turns (sent, started or asked) of every unit, in ascending Seq, with their Seq, Intent, Trigger, State, Session and SentAt.

func (*Store) RecordEvents

func (s *Store) RecordEvents(ctx context.Context, evs ...port.Event) error

RecordEvents writes evs on their units in one transaction.

func (*Store) RecordSourceEvents added in v0.3.0

func (s *Store) RecordSourceEvents(ctx context.Context, evs ...port.Event) error

RecordSourceEvents stores the events a source plugin observed on its units: a keyed one at most once per unit, kind and key, an unkeyed one at most once per unit, kind and time, where the stored one gains the actor and the data it lacks. It notes TopicSourceEvents on the units it changed.

func (*Store) Save

func (s *Store) Save(ctx context.Context, b turn.Book, evs ...port.Event) (turn.Book, error)

func (*Store) SaveApplied

func (s *Store) SaveApplied(ctx context.Context, sink string, a view.Applied, evs ...port.Event) error

func (*Store) SaveFailure

func (s *Store) SaveFailure(ctx context.Context, evs ...port.Event) error

func (*Store) SaveSession

func (s *Store) SaveSession(ctx context.Context, ses turn.Session, evs ...port.Event) error

SaveSession writes the session's row; its handles move only through BindHandle and EndHandle, so a save of a session read before its handle ended never opens it again. A save that closes the session notes TopicPlan, whose closed sessions it lists.

func (*Store) Session

func (s *Store) Session(ctx context.Context, id string) (turn.Session, bool, error)

func (*Store) SessionOf

func (s *Store) SessionOf(ctx context.Context, manager, handle string) (string, bool, error)

SessionOf is the session whose process the manager addressed by handle, the newest one when the manager gave the handle out twice.

func (*Store) SessionOfHandle

func (s *Store) SessionOfHandle(ctx context.Context, handle string) (id, manager string, ok bool, err error)

SessionOfHandle is SessionOf over every manager, for a caller that knows the handle alone; ok is false when no manager or more than one gave it out.

func (*Store) Sessions

func (s *Store) Sessions(ctx context.Context) ([]turn.Session, error)

func (*Store) TurnCounts added in v0.3.0

func (s *Store) TurnCounts(ctx context.Context, units []unit.Unit) (map[unit.Unit]int, error)

TurnCounts counts the turns on each of units; a unit with none is absent.

func (*Store) UnitEvents added in v0.3.0

func (s *Store) UnitEvents(ctx context.Context, units []unit.Unit, kinds []string, since time.Time) ([]port.Event, error)

UnitEvents are the events of units of kinds, every kind when kinds is empty, at or after since, oldest first.

func (*Store) UnitOfTurn added in v0.3.0

func (s *Store) UnitOfTurn(ctx context.Context, seq int64) (unit.Unit, bool, error)

UnitOfTurn is the unit whose book holds turn seq.

func (*Store) UnitsOf

func (s *Store) UnitsOf(ctx context.Context, handles []string) (map[string]unit.Unit, error)

func (*Store) WithTurns

func (s *Store) WithTurns(ctx context.Context, i turn.Intent) ([]unit.Unit, error)

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

Tx is a write transaction that records what it changed.

func (*Tx) DropRecord added in v0.3.0

func (tx *Tx) DropRecord(ctx context.Context, u unit.Unit, kind string) (dropped bool, err error)

DropRecord forgets u's record of kind; dropped says it kept one.

func (*Tx) PutRecord added in v0.3.0

func (tx *Tx) PutRecord(ctx context.Context, u unit.Unit, kind, actor, data string, at time.Time) error

PutRecord is DB.PutRecord in tx.

func (*Tx) Touch

func (tx *Tx) Touch(t port.Topic, units ...unit.Unit)

Touch records that the transaction changed rows of topic t for units; a store method calls it only for rows a statement changed. No units: a unit-less change.

func (*Tx) TouchAll

func (tx *Tx) TouchAll(t port.Topic)

TouchAll records a change to rows of topic t it does not enumerate.

type WakeStore added in v0.3.0

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

WakeStore is the tasks' wakes.

func (WakeStore) All added in v0.4.0

func (s WakeStore) All(ctx context.Context) ([]wake.Wake, error)

All are every task's wake.

func (WakeStore) Drop added in v0.3.0

func (s WakeStore) Drop(ctx context.Context, id task.ID) error

Drop removes task id's wake.

func (WakeStore) Due added in v0.3.0

func (s WakeStore) Due(ctx context.Context, now time.Time) ([]wake.Wake, error)

Due are the wakes whose until or expires is set and not after now.

func (WakeStore) Of added in v0.3.0

func (s WakeStore) Of(ctx context.Context, id task.ID) (wake.Wake, bool, error)

Of is task id's wake, false when it has none.

func (WakeStore) Put added in v0.3.0

func (s WakeStore) Put(ctx context.Context, w wake.Wake) error

Put sets w's task's wake, replacing the one it had.

func (WakeStore) UnitWakes added in v0.3.0

func (s WakeStore) UnitWakes(ctx context.Context, units []unit.Unit) (map[unit.Unit]wake.Wake, error)

UnitWakes are the wakes of the open tasks that hold units, by unit: the wake of a unit's oldest such task. A unit with none is absent.

func (WakeStore) Watching added in v0.3.0

func (s WakeStore) Watching(ctx context.Context) ([]wake.Wake, error)

Watching are the wakes with on or a condition set.

type WorkflowActivity

type WorkflowActivity struct {
	LastRun  time.Time // the newest done run; zero when none is stored
	Refusals int       // the step refusals since the time asked
}

WorkflowActivity is what one workflow did, as doctor reports it.

type Worktrees

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

Worktrees is the store of worktree custody.

func (Worktrees) Drop

func (w Worktrees) Drop(ctx context.Context, path string) error

Drop forgets the worktree at path and its units.

func (Worktrees) Keep

func (w Worktrees) Keep(ctx context.Context, c wsdomain.Custody) error

Keep records c's owner; a worktree already in custody keeps its creator and takes c's owner, workspace id and repository when set.

func (Worktrees) LinkUnit

func (w Worktrees) LinkUnit(ctx context.Context, path string, u unit.Unit) error

LinkUnit records that the worktree at path stands for u.

func (Worktrees) Worktree

func (w Worktrees) Worktree(ctx context.Context, path string) (wsdomain.Custody, bool, error)

Worktree is the custody of the worktree at path.

func (Worktrees) Worktrees

func (w Worktrees) Worktrees(ctx context.Context) ([]wsdomain.Custody, error)

Worktrees is every worktree in custody, by path.

Directories

Path Synopsis
Package sqlitetest seeds a store with raw SQL in tests.
Package sqlitetest seeds a store with raw SQL in tests.

Jump to

Keyboard shortcuts

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