querylog

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package querylog owns query-log history persistence: the scoped SQLite store, legacy migration, saved-queries import, and retention pruning. It has no Bubble Tea dependency; paging and rendering belong to the workbench query-log UI.

Index

Constants

View Source
const Limit = 100

Limit caps the in-memory entry list and the persisted rows per scope.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	StartedAt time.Time
	Statement string
	Duration  time.Duration
	Message   string
	Status    string // "success", "failed", "canceled"
	// Language is the backend statement language (e.g. "redis") when the
	// backend supplied it; empty for legacy entries.
	Language string
	// Replayable reports whether the statement may be copied or re-run.
	// Legacy entries and entries without metadata default to true;
	// sensitive entries are forced false before persistence.
	Replayable bool
	// Sensitive marks a statement that must never be stored verbatim.
	Sensitive bool
	// Hint is optional backend-supplied advisory guidance explaining a
	// failed execution (perk/v1 error data.hint). It is in-memory only —
	// never persisted — and never merged into Message or any identity
	// used for matching or diagnostics; the detail view renders it
	// separately, labeled, and empty means absent.
	Hint string
	// SuggestedStatement is optional backend-supplied advisory guidance:
	// a statement the user may try instead of the failed one (perk/v1
	// error data.suggested_statement). Advisory only — the workbench
	// never executes it. In-memory only, never persisted, never merged
	// into Message; empty means absent.
	SuggestedStatement string
}

Entry is one recorded query execution.

func (Entry) CanReplay

func (e Entry) CanReplay() bool

CanReplay reports whether the entry's statement may be copied or explained: sensitive entries are never replayable.

type Model

type Model struct {
	Table    table.Model
	Entries  []Entry
	Detail   *Entry
	Page     int
	PageSize int
	PendingG bool
	Column   int
	Offset   int
	// ViewportWidth is the pane content width used by Render; View and
	// root layout refreshes update it.
	ViewportWidth int
}

Model is the query-log feature component: the table pane, paging state, the selected column/offset, the detail overlay, and the entry list. Root owns the persistence store and screen geometry; the component owns every interaction and renders its own pane and overlays.

func New

func New(pageSize int) Model

New builds an empty query-log component with the given page size.

func (Model) AllEntries

func (m Model) AllEntries() []Entry

AllEntries returns the current entry list (root reads it for chat context and tests; the component owns all writes).

func (*Model) Append

func (m *Model) Append(entry Entry)

Append prepends one entry, caps the list at Limit, and re-renders.

func (*Model) Blur

func (m *Model) Blur()

Blur removes keyboard focus from the pane table.

func (*Model) ClearPendingG

func (m *Model) ClearPendingG()

ClearPendingG drops the armed top-first gate.

func (*Model) Click

func (m *Model) Click(paneX, contentY int)

Click selects the row and column under a pane click. paneX is the click x relative to the pane's content origin; contentY is relative to the pane title row (title at 0, table header at 1, data rows from 2).

func (*Model) CloseDetail

func (m *Model) CloseDetail()

CloseDetail closes the detail overlay.

func (Model) DetailOpen

func (m Model) DetailOpen() bool

DetailOpen reports whether the detail overlay is visible.

func (Model) Draw

func (m Model) Draw(canvas uv.ScreenBuffer, layout uikit.Layout)

Draw renders the detail overlay when open. The root calls Draw at the query-log detail precedence slot and draws the notification popup over the result.

func (*Model) EnsureCursor

func (m *Model) EnsureCursor()

EnsureCursor places the cursor on row 0 when the table has rows and no cursor yet (focus entry).

func (*Model) Focus

func (m *Model) Focus()

Focus gives the pane table keyboard focus.

func (Model) HasRows

func (m Model) HasRows() bool

HasRows reports whether the pane table has any rows.

func (*Model) OpenDetailAtCursor

func (m *Model) OpenDetailAtCursor()

OpenDetailAtCursor opens the detail overlay for the selected entry.

func (Model) PageCount

func (m Model) PageCount() int

PageCount returns the number of pages for the current page size.

func (*Model) RefreshViewport

func (m *Model) RefreshViewport(width int)

RefreshViewport records the pane content width and re-renders the table columns (root's layout width-change pass).

func (*Model) Render

func (m *Model) Render()

Render rebuilds the table columns and rows from the current page.

func (*Model) Reset

func (m *Model) Reset()

Reset clears the entry list, paging, selection, and detail overlay in place, keeping the sized table so the disconnect layout pass survives.

func (*Model) Resize

func (m *Model) Resize(layout uikit.Layout)

Resize records the pane viewport width and fits the table height to the pane, mirroring the root layout equation (the header line is the one-row difference between the pane height and the table viewport). Root calls it from its layout pass.

func (*Model) RevealColumn

func (m *Model) RevealColumn(viewportWidth int)

RevealColumn pans the viewport so the selected column is visible (root calls it from its layout pass).

func (*Model) Select

func (m *Model) Select(row, col int)

Select moves the cursor to row and selects column (test/API helper).

func (Model) SelectedCellText

func (m Model) SelectedCellText() (string, bool)

SelectedCellText returns the raw text of the selected cell for copying.

func (Model) SelectedEntry

func (m Model) SelectedEntry() (Entry, bool)

SelectedEntry returns the entry under the table cursor, if any.

func (Model) SelectedStatement

func (m Model) SelectedStatement() (string, bool)

SelectedStatement returns the selected entry's statement for EXPLAIN.

func (*Model) SetEntries

func (m *Model) SetEntries(entries []Entry)

SetEntries replaces the entry list and re-renders the table.

func (*Model) SetPage

func (m *Model) SetPage(page int)

SetPage sets the page and clamps the cursor to its first row.

func (Model) Summary

func (m Model) Summary() string

Summary renders the paging summary line.

func (Model) Update

func (m Model) Update(msg tea.Msg, layout uikit.Layout, keys uikit.KeyMatcher) (Model, uikit.Event, tea.Cmd)

Update handles query-log messages: the detail overlay consumes everything while open; otherwise the pane's keybindings, table passthrough, and pending-G logic run. The context-menu key and the pane focus switch stay in root (they need screen geometry); root routes them before calling Update. Events ask root for side effects the component cannot perform itself.

func (Model) View

func (m Model) View(layout uikit.Layout) string

View renders the query-log pane body: the table viewport, the summary line, and the status row. It is pure: root refreshes the component's viewport width through SetViewportWidth when the layout changes.

func (*Model) Wheel

func (m *Model) Wheel(step, hStep int)

Wheel moves the cursor row (step) and selected column (hStep).

type Store

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

Store is a lazily opened scoped query-log database shared by every save and load. It owns exactly one *sql.DB.

func Open

func Open(path string, retentionDays int) (*Store, error)

Open opens (creating and migrating if needed) the query-log database at path. retentionDays is the resolved history window applied on each prune; 0 discards history for a scope immediately.

func (*Store) Append

func (s *Store) Append(connectionID string, entry Entry, limit int) error

Append persists one entry for a connection scope: prune by retention, insert, then trim to the limit. It rejects an empty scope so an unscoped row is never written.

func (*Store) Close

func (s *Store) Close() error

Close releases the underlying database.

func (*Store) Load

func (s *Store) Load(connectionID string, limit int) ([]Entry, error)

Load returns the retained entries for one connection scope, newest first. An empty scope never reads unscoped rows and returns no entries.

Jump to

Keyboard shortcuts

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