db

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package db wires gitrakz's SQLite storage: opening the database, running the embedded migrations, and exposing a typed Store facade over the generated gorm-gen repositories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is the typed facade over gitrakz's SQLite storage. It maps between the domain types (types.Event, template.Template, ...) and the generated gorm-gen repositories, wraps every error with ctxerrors, and translates gorm's not-found result into either a zero value or commerr.ErrNotFound depending on what each method's caller needs.

func Open

func Open(_ context.Context, dbPath string) (*Store, error)

Open opens (creating it if necessary) the SQLite database at dbPath, runs every pending migration, and returns a Store wired to its own generated query API instance (repositories.Use, not repositories.SetDefault — the latter mutates process-wide globals and races when more than one Store is opened concurrently, which every parallel test in this package does). ctx is accepted for API consistency with the rest of the codebase; the underlying driver and migration runner are synchronous and do not currently accept a context.

func (*Store) Close

func (s *Store) Close() error

Close releases the underlying database connection.

func (*Store) DeleteTemplate

func (s *Store) DeleteTemplate(ctx context.Context, id string) error

DeleteTemplate removes the template with the given id, if any.

func (*Store) GetSyncState

func (s *Store) GetSyncState(
	ctx context.Context,
	owner, repo string,
) (int64, error)

GetSyncState returns the last synced unix timestamp for (owner, repo), or 0 with a nil error if no sync has ever run for that pair.

func (*Store) GetTemplate

func (s *Store) GetTemplate(
	ctx context.Context,
	id string,
) (template.Template, error)

GetTemplate returns the template with the given id, or wraps commerr.ErrNotFound if no template has that id.

func (*Store) LLMCacheGet

func (s *Store) LLMCacheGet(
	ctx context.Context,
	key string,
) (string, bool, error)

LLMCacheGet returns the cached output for key, or ok=false with a nil error if key was never cached.

func (*Store) LLMCachePut

func (s *Store) LLMCachePut(
	ctx context.Context,
	key, step, processingVersion, inputHash, output string,
) error

LLMCachePut stores output under key, replacing any previous entry for that key.

func (*Store) ListOwners

func (s *Store) ListOwners(ctx context.Context) ([]string, error)

ListOwners returns every distinct owner with at least one stored event, sorted ascending.

func (*Store) ListRepos

func (s *Store) ListRepos(ctx context.Context, owner string) ([]string, error)

ListRepos returns every distinct repo owner has at least one stored event for, sorted ascending.

func (*Store) ListTemplates

func (s *Store) ListTemplates(
	ctx context.Context,
) ([]template.Template, error)

ListTemplates returns every saved template.

func (*Store) QueryTimeline

func (s *Store) QueryTimeline(
	ctx context.Context,
	f TimelineFilter,
) ([]types.Event, bool, error)

QueryTimeline returns the events matching f, newest first, one page at a time. hasMore reports whether a further page exists; when true, the last row of a full page has already been dropped from evs.

func (*Store) SaveDocument

func (s *Store) SaveDocument(
	ctx context.Context,
	id, templateID, filter, formValues, doc string,
) error

SaveDocument persists one template run's output under id.

func (*Store) SaveTemplate

func (s *Store) SaveTemplate(
	ctx context.Context,
	tmpl template.Template,
) error

SaveTemplate creates tmpl, or replaces every column of the existing row with the same id.

func (*Store) UpsertEvents

func (s *Store) UpsertEvents(ctx context.Context, evs []types.Event) error

UpsertEvents inserts evs, updating any row whose id already exists. A nil or empty evs is a no-op.

func (*Store) UpsertSyncState

func (s *Store) UpsertSyncState(
	ctx context.Context,
	owner, repo string,
	ts int64,
) error

UpsertSyncState records ts as the last synced unix timestamp for (owner, repo), replacing any previous value.

type TimelineFilter

type TimelineFilter struct {
	Owner   string
	Repo    string
	Type    string
	From    int64
	To      int64
	Page    int
	PerPage int
}

TimelineFilter narrows QueryTimeline to a window of events. The zero value of every field means "no filter on that dimension" — From/To of 0 disable the time bound, Owner/Repo/Type of "" disable that equality filter.

Directories

Path Synopsis
Package migrations embeds gitrakz's SQLite schema migrations into the binary so it stays self-contained — no migrations directory to mount, no version skew between the binary and the SQL files.
Package migrations embeds gitrakz's SQLite schema migrations into the binary so it stays self-contained — no migrations directory to mount, no version skew between the binary and the SQL files.

Jump to

Keyboard shortcuts

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